Comma-separated String into Table's Column in SQL Server

前端 未结 3 1998
一个人的身影
一个人的身影 2020-12-11 11:39

I am working with SQL Server, I have successfully converted a table\'s rows into comma-separated values, now I want to convert that string of comma-separated values back to

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 12:05

    This question is a duplicate of a few others, but some of the accepted answers are still the inefficient WHILE loops or recursive CTEs. There are three ways to accomplish a split that won't kill performance:

    • Numbers / Tally Table: http://www.sqlservercentral.com/articles/Tally+Table/72993/ (free registration required)

    • XML: https://www.simple-talk.com/blogs/2012/01/05/using-xml-to-pass-lists-as-parameters-in-sql-server/

    • SQLCLR: there are numerous examples of this on many sites but your best (and easiest) bet is to either grab the one provided in the Numbers / Tally Table article noted above OR just install SQL# (SQLsharp) (I am the author of SQL# but String_Split and String_Split4k are in the Free version).

提交回复
热议问题