Which code segment should you use?

You have a table named Stores that has an XML column named OpenHours.
This column contains the opening and closing times.
<hours dayofWeek= "Monday" open ="8:00 AM" closed="8:00 PM"
<hours dayofWeek= "Tuesday" open ="8:00 AM" closed="8:00 PM"

<hours dayofWeek= "Saturday" open ="8:00 AM" closed="8:00 PM"

You need to write a query that returns a list of stores and their opening time for a specified day.
Which code segment should you use?

You have a table named Stores that has an XML column named OpenHours.
This column contains the opening and closing times.
<hours dayofWeek= "Monday" open ="8:00 AM" closed="8:00 PM"
<hours dayofWeek= "Tuesday" open ="8:00 AM" closed="8:00 PM"

<hours dayofWeek= "Saturday" open ="8:00 AM" closed="8:00 PM"

You need to write a query that returns a list of stores and their opening time for a specified day.
Which code segment should you use?

A.
DECLARE @Day VARCHAR(10) = ‘Tuesday’
SELECT StoreName, OpenHours.value(‘/hours[1]/@open’,’time’)
FROM Stores WHERE OpenHours.value(‘/hours[1]/@dayofWeek’,’varchar(20)’) = @Day

B.
DECLARE @Day VARCHAR(10) = ‘Tuesday’
SELECT StoreName, OpenHours.value(‘/hours[1]/@open’,’time’)
FROM Stores WHERE OpenHours.exist(‘/hours[@dayofWeek=sql:variable("@Day")]’) = 1

C.
DECLARE @Day VARCHAR(10) = ‘Tuesday’
SELECT Storename, OpenHours.query(‘data(/hours[@dayofWeek=sql:variable("@Day")]/@open)’)
FROM Stores D. DECLARE @Day VARCHAR(10) = ‘Tuesday’

D.
SELECT StoreName, OpenHours.value(‘/hours[1][@dayofWeek=sql:variable("@Day")]/@open’,’time’)
FROM Stores



Leave a Reply 0

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