Splitting the string in sql server

前端 未结 4 1098
独厮守ぢ
独厮守ぢ 2020-11-27 19:18

I have a string in the database which is comma separated.Like \'apple,banana,pineapple,grapes\' I need to split this string on the basis of comma and iterate through this.Si

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 19:56

    ... Since there is no built in function in sql server ...

    That was true at the time you asked this question but SQL Server 2016 introduces STRING_SPLIT.

    So you can just use

    SELECT value
    FROM   STRING_SPLIT ('apple,banana,pineapple,grapes', ',') 
    

    There are some limitations (only single character delimiters accepted and a lack of any column indicating the split index being the most eye catching). The various restrictions and some promising results of performance testing are in this blog post by Aaron Bertrand.

提交回复
热议问题