You administer a Microsoft SQL Server 2012 database named ContosoDb. Tables are
defined as shown in the exhibit. (Click the Exhibit button.)
You need to display rows from the Orders table for the Customers row having the
CustomerId value set to 1 in the following XML format.
<CUSTOMERS Name=”Customer A” Country=”Australia”>
<ORDERS OrderID=”1″ OrderDate=”2001 -01 -01″ Amount=”3400.00″ />
<ORDERS OrderID=”2″ OrderDate=”2002-01 -01″ Amount=”4300.00″ />
</CUSTOMERS>
Which Transact-SQL query should you use?
A.
SELECT OrderId, OrderDate, Amount, Name, Country
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE Customers.CustomerId = 1
FOR XML RAW
B.
SELECT OrderId, OrderDate, Amount, Name, Country
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE Customers.CustomerId = 1
FOR XML RAW, ELEMENTS
C.
SELECT OrderId, OrderDate, Amount, Name, Country
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE Customers.CustomerId = 1
FOR XML AUTO
D.
SELECT OrderId, OrderDate, Amount, Name, Country
FROM Orders INNER JOIN Customers ON Orders.CustomerId – Customers.CustomerId
WHERE Customers.CustomerId= 1
FOR XML AUTO, ELEMENTS
E.
SELECT Name, Country, OrderId, OrderDate, Amount
FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId
WHERE Customers.CustomerId= 1
FOR XML AUTO
F.
SELECT Name, Country, Orderld, OrderDate, Amount
FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId
WHERE Customers.CustomerId= 1
FOR XML AUTO, ELEMENTS
G.
SELECT Name AS ‘@Name’, Country AS ‘@Country’, OrderId, OrderDate, Amount
FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId
WHERE Customers.CustomerId= 1
FOR XML PATH (‘Customers’)
H.
SELECT Name AS ‘Customers/Name’, Country AS ‘Customers/Country’, OrderId,
OrderDate, Amount
FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId
WHERE Customers.CustomerId= 1
FOR XML PATH (‘Customers’)
SELECT C.contactname, C.country, O.orderid, O.orderdate, O.freight
FROM Sales.Orders AS O
INNER JOIN Sales.Customers AS C
ON O.custid= C.custid
WHERE C.custid= 1
FOR XML AUTO;
RESULT:
——————————————————————————–
SELECT C.contactname, C.country, O.orderid, O.orderdate, O.freight
FROM Sales.Orders AS O
INNER JOIN Sales.Customers AS C
ON O.custid= C.custid
WHERE C.custid= 1
FOR XML AUTO, ELEMENTS;
RESULT:
Allen, Michael
Germany
10643
2007-08-25T00:00:00
29.4600
10692
2007-10-03T00:00:00
61.0200
10702
2007-10-13T00:00:00
23.9400
10835
2008-01-15T00:00:00
69.5300
10952
2008-03-16T00:00:00
40.4200
11011
2008-04-09T00:00:00
1.2100
E : FOR XML AUTO