Split function equivalent in T-SQL?

后端 未结 15 1860
深忆病人
深忆病人 2020-11-21 07:23

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

15条回答
  •  遥遥无期
    2020-11-21 08:10

    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

提交回复
热议问题