我正在尝试完成一项家庭作业,以创建,插入,修改和xquery XML表。到目前为止,我已经能够创建表并插入一些数据行;但是,我被困在修改过的部分。我已创建查询并成功执行,但未插入新的材料节点。我必须在所有功能节点下插入此子节点。
CREATE TABLE Prod_Catalog
(
ID int NOT NULL Primary Key,
xCol xml NOT NULL,
)
-
INSERT INTO dbo.Prod_Catalog VALUES
(1,'<root><productdescription ProductID="P5500xs" ProductName="Brava 55 TV">
<features>Features
<warranty>5 years</warranty>
<maintenance>Dont hit with hammer</maintenance>
</features></productdescription>
</root>'),
(2,'<root><productdescription ProductID="G29-2" ProductName="Panasonic 1100Watt Microwave">
<features>Features
<warranty>1 year</warranty>
<maintenance>Dont cook metal forks!</maintenance>
</features></productdescription>
</root>'),
(3,'<root><productdescription ProductID="LG22-XL" ProductName="LG 20 cubic refrigerator">
<features>Features
<warranty>1 year</warranty>
<maintenance>Makes things cold.</maintenance>
</features></productdescription>
</root>')
-
UPDATE dbo.Prod_Catalog
SET xCol.modify('insert <materials>Electronics,Glass,Flashy Lights</materials> as first into (/root/productiondescription[@ProductID=("P5500xs")]/features)[1]');
GO
-
(3 row(s) affected)
-
<root><productdescription ProductID="P5500xs" ProductName="Brava 55 TV"><features>Features<warranty>5 years</warranty><maintenance>Dont hit with hammer</maintenance></features></productdescription></root>
<root><productdescription ProductID="G29-2" ProductName="Panasonic 1100Watt Microwave"><features>Features<warranty>1 year</warranty><maintenance>Dont cook metal forks!</maintenance></features></productdescription></root>
<root><productdescription ProductID="LG22-XL" ProductName="LG 20 cubic refrigerator"><features>Features<warranty>1 year</warranty><maintenance>Makes things cold.</maintenance></features></productdescription></root>
-
非常感谢任何有关真正工作的建议或指示。
谢谢!
答案 0 :(得分:0)
生产描述不是元素名称。产品描述是。 - Damien_The_Unbeliever 13小时前
达明,
那就做到了。谢谢第二双眼睛。
JHG