Comma separated results in SQL

后端 未结 5 1154
我寻月下人不归
我寻月下人不归 2020-11-22 03:24

I have the following code which will create a comma delimited list for my results:

DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+\', \' ,         


        
5条回答
  •  囚心锁ツ
    2020-11-22 03:46

    this works in sql server 2016

    USE AdventureWorks
    GO
    DECLARE @listStr VARCHAR(MAX)
    SELECT @listStr = COALESCE(@listStr+',' ,'') + Name
    FROM Production.Product
    SELECT @listStr
    GO
    

提交回复
热议问题