Split function equivalent in T-SQL?

后端 未结 15 1859
深忆病人
深忆病人 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 07:59

    You've tagged this SQL Server 2008 but future visitors to this question (using SQL Server 2016+) will likely want to know about STRING_SPLIT.

    With this new builtin function you can now just use

    SELECT TRY_CAST(value AS INT)
    FROM   STRING_SPLIT ('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15', ',') 
    

    Some restrictions of this function and some promising results of performance testing are in this blog post by Aaron Bertrand.

提交回复
热议问题