Which query should you use?

You have a table named Customer that has anXML column named Locations. This column stores anX ML fragment that contains details of one or more locations, as show in the following examples.

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?

You have a table named Customer that has anXML column named Locations. This column stores anX ML fragment that contains details of one or more locations, as show in the following examples.

<Location City=”Sydney”Address=”…” PhoneNumber=”…” />
<Location City=”Chicago”Address=”…” Pho neNumber=”…” />
<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,
Locations.query(‘for $i in /Location return data($i/@City)’),
Locations.query(‘ for $i in /Location return $i’)
FROM Customer

B.
SELECT
CustomerName,
Locations.query(‘for $i in /Location return element Location {$i/@City, $i}’)
FROM Customer

C.
SELECT
CustomerName,
Locations.query(‘data(/Location/@City)’), Locations.query(‘/Location’)
FROM Customer

D.
SELECT
CustomerName,
Loc.value(‘@City’,’varchar(100)’),
Loc.query(‘.’)
FROM Customer
CROSS APPLY Customer.Locations.nodes (‘/Location’) Locs(Loc)



Leave a Reply 0

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