SQL XML将属性插入节点

时间:2017-08-21 14:19:02

标签: sql xml

我需要将一个属性tag ='plan'添加到带有节点Image的列tisa_LayoutURL中。请参阅下面的查询

select @xml = 
    (
            SELECT art.tisa_Code AS [@internal-id],
                cla.tisa_image1 AS [image], '',
                cla.tisa_image2 AS [image], '',
                cla.tisa_image3 AS [image], '',
                cla.tisa_image4 AS [image], '',
                art.tisa_LayoutUrl AS [image],
                addr.tisa_Description AS [description]
    FROM tisa_article art JOIN 
         tisa_Address addr ON addr.tisa_AddressId = art.tisa_AddressId JOIN
         tisa_Classifier cla ON cla.tisa_classifierid = addr.tisa_classifierid 
    JOIN
         Account Acc ON Acc.AccountId=cla.tisa_vendorid
    FOR XML PATH('offer'), root('realty-feed'))

我需要获得以下内容:

<image>xxxxx.jpg</image>
<image>xxxx1.jpg</image>
<image>xxxx2.jpg</image>
<image>xxxx3.jpg</image>
<image tag="plan">xxxx4.jpg</image>

如何修改我的查询以实现这一目标?

1 个答案:

答案 0 :(得分:1)

替换

art.tisa_LayoutUrl AS [image],

使用:

'plan' AS "image/@tag",
art.tisa_LayoutUrl AS [image],