Which Transact-SQL statement should you use?

You manage a database on an instance of SQL Server 2008 for a large training company.
You have the following Transact-SQL:
DECLARE @xmldoc xml
SET @xmldoc=’
<EventData>
<Event ID="C-012" EventDesc="Using Microsoft Word 2007" EventLoc="Southeast Campus">
<Coordinator>Beth Jackson</Coordinator>
<AvailSeats>35</AvailSeats>
<Enrolled>10</Enrolled>
</Event>
<Event ID="C-057" EventDesc="SQL Server 2008 Basics" EventLoc="Main Campus"><Coordinator>Ross Moore</
Coordinator><AvailSeats>30</AvailSeats><Enrolled>15</Enrolled></Event><Event ID="M-023" EventDesc="Time Management 101"
EventLoc="Adair Center"><Coordinator>Helen Lewis</Coordinator><AvailSeats>45</AvailSeats><Enrolled>30</Enrolled></Event>
</EventData>’
You want to extract data from the XML document and insert it into a new table named EventList. The new table should contain a row for each event that includes the following columns:
EventID - The ID attribute value for the event
Description - The EventDesc attribute value for the event
Location - The EventLoc attribute value for the event
Which Transact-SQL statement should you use?
A. SELECT x.Event.value(‘@ID[1]’, ‘varchar(10)’) AS EventID,x.Event.value(‘@EventDesc[1]’, ‘varchar(35)’) AS
Description,x.Event.value(‘@EventLoc[1]’, ‘varchar(25)’) AS Location
INTO EventList
FROM @xmldoc.nodes(‘//EventData/Event’) AS x(Event);
B. SELECT
@xmldoc.query(‘/EventData/Event[@ID]’) AS EventID,@xmldoc.query(‘/EventData/Event[@EventDesc]’) AS
Description,@xmldoc.query(‘/EventData/Event[@EventLoc]’) AS Location
INTO EventList
FROM @xmldoc.nodes(‘//EventData/Event’) AS x(Event);
C. SELECT
@xmldoc.query(‘/EventData/Event/@ID’) AS EventID,@xmldoc.query(‘/EventData/Event/@EventDesc’) AS
Description,@xmldoc.query(‘/EventData/Event/@EventLoc’) AS Location
INTO EventList
FROM @xmldoc.nodes(‘//EventData/Event’) AS x(Event);
D. SELECT
@xmldoc.value(‘/EventData/Event/@ID’, ‘varchar(10)’) AS EventID,@xmldoc.value(‘/EventData/Event/@EventDesc’, ‘varchar (35)’) AS Description,@xmldoc.value(‘/EventData/Event/@EventLoc’, ‘varchar(25)’) AS Location
INTO EventList
FROM @xmldoc.nodes(‘//EventData/Event’) AS x(Event);

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.