Which query should you use?

You have a table named Customer that has an XML column named Locations. This column stores an XML fragment that contains details of one or more locations, as show in the following examples.
<Location City="Sydney" Address="…" PhoneNumber="…" /><Location City="Chicago"
Address="…" PhoneNumber="…" /><Location City="London" Address="…" PhoneNumber="…" />
You need to write a query that returns a row for each of the customer’s locations. Each resulting row must include the customer name, city, and an XML fragment that contains the location details.
Which query should you use?
A. SELECT CustomerName,Loc.value(‘@City’,’varchar(100)’),Loc.query(‘.’)
FROM Customer
CROSS APPLY Customer.Locations.nodes (‘/Location’) Locs(Loc)
B. SELECT CustomerName,Locations.query(‘for $i in /Location return data($i/@City)’),Locations.query(‘for $i in /Location return $i’)
FROM Customer
C. SELECT CustomerName,Locations.query(‘data(/Location/@City)’),Locations.query(‘/Location’)
FROM Customer
D. SELECT CustomerName,Locations.query(‘for $i in /Location return element Location {$i/@City,$i}’)
FROM Customer

microsoft-exams

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.