Which query should you use?

You have the following XML document that contains Product information.
DECLARE @prodList xml =’
<ProductList xmlns=”urn:Wide_World_Importers/schemas/Products”>
<Product Name=”Product1″ Category=”Food” Price=”12.3″ />
<Product Name=”Product2″ Category=”Drink” Price=”1.2″ />
<Product Name=”Product3″ Category=”Food” Price=”5.1″ />

</ProductList>’;
You need to return a list of products that contains the Product Name, Category, and Price of each
product.
Which query should you use?

You have the following XML document that contains Product information.
DECLARE @prodList xml =’
<ProductList xmlns=”urn:Wide_World_Importers/schemas/Products”>
<Product Name=”Product1″ Category=”Food” Price=”12.3″ />
<Product Name=”Product2″ Category=”Drink” Price=”1.2″ />
<Product Name=”Product3″ Category=”Food” Price=”5.1″ />

</ProductList>’;
You need to return a list of products that contains the Product Name, Category, and Price of each
product.
Which query should you use?

A.
SELECT prod.value(‘.[1]/@Name’,’varchar(100)’),
prod.value(‘.[1]/@Category’,’varchar(20)’),
prod.value(‘.[1]/@Price’,’money’)
FROM @prodList.nodes(‘/ProductList/Product’) ProdList(prod);

B.
SELECT prod.value(‘@Name’,’varchar(100)’),
prod.value(‘@Category’,’varchar(20)’),
prod.value(‘@Price’,’money’)
FROM @prodList.nodes(‘/ProductList/Product’) ProdList(prod);

C.
WITH XMLNAMESPACES(DEFAULT ‘urn;Wide_World_Importers/schemas/Products’ as o)
SELECT prod.value(‘Name[1]’,’varchar(100)’),
prod.value(‘Category[1]’,’varchar(20)’),

prod.value(‘Price[1]’,’money’)
FROM @prodList.nodes(‘/o:ProductList/o:Product’) ProdList(prod);

D.
WITH XMLNAMESPACES(DEFAULT ‘urn:Wide_World_Importers/schemas/Products’)
SELECT prod.value(‘./@Name’,’varchar(100)’),
prod.value(‘./@Category’,’varchar(20)’),
prod.value(‘./@Price’,’money’)
FROM @prodList.nodes(‘/ProductList/Product’) ProdList(prod);



Leave a Reply 0

Your email address will not be published. Required fields are marked *