I’m looking to split \'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15...\' (comma delimited) into a table or table variable.
Does anyone have a function that returns each one
DECLARE
@InputString NVARCHAR(MAX) = 'token1,token2,token3,token4,token5'
, @delimiter varchar(10) = ','
DECLARE @xml AS XML = CAST((''+REPLACE(@InputString,@delimiter ,' ')+' ') AS XML)
SELECT C.value('.', 'varchar(10)') AS value
FROM @xml.nodes('X') as X(C)
Source of this response: http://sqlhint.com/sqlserver/how-to/best-split-function-tsql-delimited