简体   繁体   English

SQL XML插入节点的属性

[英]SQL XML Insert attribute to node

I need to add an attribute tag='plan' to the column tisa_LayoutURL with the node Image. 我需要在带有节点Image的tisa_LayoutURL列中添加一个属性tag ='plan'。 See my query below 请参阅下面的查询

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'))

I need to obtain the following: 我需要获得以下内容:

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

how can i modify my query to achieve that? 我如何修改我的查询以实现这一目标?

Replace the line 更换线

art.tisa_LayoutUrl AS [image],

with: 有:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM