SQL Server FOR XML Path make repeating nodes

前端 未结 5 1730
[愿得一人]
[愿得一人] 2020-12-01 22:05

I\'d like to generate the following output using SQL Server 2012:


  1
  2
  3<         


        
5条回答
  •  渐次进展
    2020-12-01 22:44

    I think if you change the alias of the columns like this it should work. This is because the aliases are same and may be the data type of data is same as well. In case if you have different data in col1, col2 and col3, it shouldn't be showing this behaviour.

    SELECT 
    t.col1 as 'item'
    ,t.col2 as 'item1'
    ,t.col3 as 'item2' 
    FROM tbl t 
    FOR XML PATH('parent'), TYPE
    

提交回复
热议问题