How do I remove redundant namespace in nested query when using FOR XML PATH

前端 未结 6 1944
长情又很酷
长情又很酷 2020-11-28 12:54

UPDATE: I\'ve discovered there is a Microsoft Connect item raised for this issue here

When using FOR XML PATH

6条回答
  •  情书的邮戳
    2020-11-28 13:22

    An alternative solution I've seen is to add the XMLNAMESPACES declaration after building the xml into a temporary variable:

    declare @xml as xml;
    select @xml = (
    select 
        a.c2 as "@species"
        , (select l.c3 as "text()" 
           from t2 l where l.c2 = a.c1 
           for xml path('leg'), type) as "legs"
    from t1 a
    for xml path('animal'))
    
    ;with XmlNamespaces( 'uri:animal' as an)
    select @xml for xml path('') , root('zoo');
    

提交回复
热议问题