How to concatenate all columns in a select with SQL Server

后端 未结 5 915
借酒劲吻你
借酒劲吻你 2020-12-03 12:45

I need my select to have a pattern like this:

 SELECT \' \' + tbl.* + \' \' FROM table tbl;

The ideal solution wo

5条回答
  •  时光取名叫无心
    2020-12-03 13:24

    Try the code below:

    SELECT Stuff(
    (SELECT N', ' + COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
    where TABLE_NAME = 'YourTableName' FOR XML PATH(''),TYPE)
    .value('text( [1]','nvarchar(max)'),1,2,N'')
    

提交回复
热议问题