Обновление запроса SQL Server 2014 для вставки узла XML успешно, но без вставки узла
Я пытаюсь выполнить домашнее задание, чтобы создать, вставить, изменить и запросить таблицу 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>
-
Любой совет или направление, чтобы заставить это действительно работать, высоко ценится.
Спасибо!
1 ответ
productiondescription не является именем элемента. Описание продукта есть. - Damien_The_Unbeliever 13 часов назад
Дамьен,
Это сделал это. Спасибо за вторую пару глаз.
JHG