Using SQL Server built into XML parsing is also an option. Of course, this overshadows all the nuances of a CSV compatible with RFC-4180.
-- Given a CSV string like this: declare @roles varchar(800) select @roles = 'Pub,RegUser,ServiceAdmin' -- Here the XML way select split.csv.value('.', 'varchar(100)') as value from ( select cast('<x>' + replace(@roles, ',', '</x><x>') + '</x>' as xml) as data ) as csv cross apply data.nodes('/x') as split(csv)
If you are using SQL 2016+, it is better to use string_split , but this is the usual way to do this before SQL 2016.
mattmc3
source share