Comma Delimited SQL string Need to separated

前端 未结 11 1954
[愿得一人]
[愿得一人] 2020-12-20 23:39

I have this string that i am getting from .net application A,B,C,D,E,F,

I wanted to write a sql select statement like

set @string = \'A,B,C,D,E,F\'

         


        
11条回答
  •  轮回少年
    2020-12-21 00:40

    Very frequently asked question! What you want is a table-valued function.

    But don't reinvent the wheel by writing your own, I found dozens just by Googling sql split. Here's one from Microsoft:

    http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=StringArrayInput

    I used to use dynamic SQL for this, but that meant I had to dig up the code and copy it into each new app. Now I don't even have to think about it.

提交回复
热议问题