使用ELEMENTS方式,
查询语句:
SELECT CategoryID,
Picture
FROM Categories
WHERE CategoryID = 1
FOR XML AUTO,ELEMENTS
返回结果:
<;Categories>
<;CategoryID>1<;/CategoryID>
<;Picture>dbobject/Categories[@CategoryID='1']/@Picture<;/Picture>
<;/Categories>
二。使用RAW模式
使用RAW模式不能使用ELEMENTS选项。
1.简单查询
查询语句:
SELECT CategoryID,
CategoryName AS Nanme
FROM Categories
WHERE CategoryID <; 3
ORDER BY CategoryID DESC
FOR XML RAW
返回结果:
<;row CategoryID="2" Nanme="Condiments"/>
<;row CategoryID="1" Nanme="Beverages"/>
2.连接查询
查询语句:
SELECT Categories.CategoryID,
Categories.CategoryName,
ProductID,
ProductName
FROM Categories
JOIN Products ON Categories.CategoryID = Products.CategoryIDand ProductID <;4
WHERE Categories.CategoryID <;= 2FOR XML RAW
返回结果:
<;row CategoryID="1" CategoryName="Beverages" ProductID="1" ProductName="Chai"/>
<;row CategoryID="1" CategoryName="Beverages" ProductID="2" ProductName="Chang"/>
<;row CategoryID="2" CategoryName="Condiments" ProductID="3" ProductName="Aniseed Syrup"/>
评论加载中…
![]() |