Using attribute more than once in FOR XML Path T-SQL query with same element name

后端 未结 3 796
臣服心动
臣服心动 2021-01-26 18:41

I am trying to create an xml output in SQL 2008 using FOR XML Path. This is working fine:


      Clothing         


        
3条回答
  •  太阳男子
    2021-01-26 18:49

    I know this is an old post, but I want to share one solution that avoids that FOR XML EXPLICIT command complexity for big xmls.

    It's enough to add null as a child of Taxonomy, and error will disappear:

        select 1 as 'Taxonomy/Category/@Level',
               t.MainCat as 'Taxonomy/Category',
               NULL AS 'Taxonomy/*',
               2 as 'Taxonomy/Category/@Level',
               t.SubCat as 'Taxonomy/Category',
        from t
    

    I hope it helps.

提交回复
热议问题