我想使用xml.modify命令动态创建一个XML文件。我有一个表,其中有一个类型为xml的列,我将使用游标读取该表并创建一个XML文件。
我尝试这段代码只是为了做一些测试,但是它不能工作。
declare @root xml
declare @x xml
set @root = '<Shipment></Shipment>'
set @x = '<ShipmentHeader><ShipID>0001</ShipID></ShipmentHeader>'
select @x
set @root.modify('insert {sql:variable("@x")} into (/Shipment)')
select @root我会做的
<Shipment>
<ShipmentHeader>
<ShipID>0001</ShipID>
</ShipmentHeader>
</Shipment> 发布于 2014-12-10 21:19:11
我修复后,我自己修改了一点的代码,工作代码如下
declare @x xml
set @root = '<Shipment></Shipment>'
set @x = '<ShipmentHeader><ShipID>0001</ShipID></ShipmentHeader>'
select @x
set @root.modify('insert (sql:variable("@x")) into (/Shipment)[1]')
select @root我删除了{}并指定了Shipment1的第一个节点,这样我就得到了预期的结果
https://stackoverflow.com/questions/27399898
复制相似问题