How to choose returned column name in a SELECT FOR XML query?

后端 未结 6 789
时光取名叫无心
时光取名叫无心 2021-02-06 20:49

MS SQL has a convenient workaround for concatenating a column value from multiple rows into one value:

SELECT col1
 FROM table1
 WHERE col2 = \'x\'
 ORDER by col         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 21:22

    That should do:

    select(
    SELECT col1
     FROM table1
     WHERE col2 = 'x'
     ORDER by col3
     FOR XML path('')
    ) as myName
    

    Not pretty but should give the result that you need

提交回复
热议问题