ListAGG in SQLSERVER

后端 未结 4 1274
心在旅途
心在旅途 2020-11-21 22:22

I\'m trying to aggregate a \'STRING\' field in SQLServer. I would like to find the same function LISTAGG like in Oracle .

Do you know how to do the same function or

4条回答
  •  粉色の甜心
    2020-11-21 23:00

    In SQL Server 2017 STRING_AGG is added:

    SELECT t.name,STRING_AGG (c.name, ',') AS csv
    FROM sys.tables t
    JOIN sys.columns c on t.object_id = c.object_id
    GROUP BY t.name
    ORDER BY 1
    

    Also, STRING_SPLIT is usefull for the opposite case and available in SQL Server 2016

提交回复
热议问题