|
DECLARE @TestStringValue nvarchar(1024);
SET @TestStringValue = (SELECT ProductID,[Name] FROM Production.Product
WHERE ProductSubcategoryID = 9
FOR XML AUTO);
SELECT @TestStringValue;
|
|
<Production.Product ProductID="894" Name="Rear Derailleur"/><Production.Product ProductID="945" Name="Front Derailleur"/>
|
|
DECLARE @TestStringValue nvarchar(1024);
SET @TestStringValue = (SELECT ProductID,[Name] FROM Production.Product
WHERE ProductSubcategoryID = 9
FOR XML AUTO,TYPE);
|
|
DECLARE @XmlTestValue xml;
SET @XmlTestValue = (SELECT ProductID,[Name] FROM Production.Product
WHERE ProductSubcategoryID = 9
FOR XML AUTO,TYPE);
SELECT @XmlTestValue;
|
|
SELECT ProductSubcategoryID,[Name] ,
(SELECT ProductID,[Name] FROM Production.Product Product
WHERE ProductSubcategoryID = 9
FOR XML AUTO,TYPE) AS Products
FROM Production.ProductSubcategory AS Category
WHERE ProductSubcategoryID = 9
FOR XML AUTO;
|
|
<CategoryProductSubcategoryID="9"Name="Derailleurs">
<Products>
<ProductProductID="894"Name="Rear Derailleur" />
<ProductProductID="945"Name="Front Derailleur" />
</Products>
</Category>
|
|
<CategoryProductSubcategoryID="9"Name="Derailleurs"Products="<Product ProductID="894" Name="Rear Derailleur"/><Product ProductID="945" Name="Front Derailleur"/>" />
|
|
WITH XMLNAMESPACES ('uri0' as ns0)
SELECT ProductSubcategoryID,[Name] ,
(SELECT ProductID,[Name] FROM Production.Product Product
WHERE ProductSubcategoryID = 9
FOR XML RAW('ns0:Product'),TYPE) AS 'ns0:Products'
FROM Production.ProductSubcategory AS Category
WHERE ProductSubcategoryID = 9
FOR XML RAW('ns0:Category'),ROOT('ns0:Message');
|
|
<ns0:Messagexmlns:ns0="uri0">
<ns0:CategoryProductSubcategoryID="9"Name="Derailleurs">
<ns0:Products>
<ns0:Productxmlns:ns0="uri0"ProductID="894"Name="Rear Derailleur" />
<ns0:Productxmlns:ns0="uri0"ProductID="945"Name="Front Derailleur" />
</ns0:Products>
</ns0:Category>
</ns0:Message>
|
|
WITH XMLNAMESPACES (DEFAULT 'http://blog.csdn.net/zhzuo')
SELECT ProductSubcategoryID,[Name] ,
(SELECT ProductID,[Name] FROM Production.Product Product
WHERE ProductSubcategoryID = 9
FOR XML AUTO,TYPE) AS Products
FROM Production.ProductSubcategory AS Category
WHERE ProductSubcategoryID = 9
FOR XML AUTO,ROOT('Message');
|
|
<Messagexmlns="http://blog.csdn.net/zhzuo">
<CategoryProductSubcategoryID="9"Name="Derailleurs">
<Products>
<Productxmlns="http://blog.csdn.net/zhzuo"ProductID="894"Name="Rear Derailleur" />
<Productxmlns="http://blog.csdn.net/zhzuo"ProductID="945"Name="Front Derailleur" />
</Products>
</Category>
</Message>
|
|
WITH XMLNAMESPACES (DEFAULT 'http://blog.csdn.net/zhzuo')
SELECT ProductID AS 'Product/@ProductID',
Name AS 'Product/Name'
FROM Production.Product
WHERE ProductSubcategoryID = 9
FOR XML PATH(''),ROOT('Products');
|
|
<Productsxmlns="http://blog.csdn.net/zhzuo">
<ProductProductID="894">
<Name>Rear Derailleur</Name>
</Product>
<ProductProductID="945">
<Name>Front Derailleur</Name>
</Product>
</Products>
|
发表于 @ 2008年06月08日 22:08:00 | 评论( loading... ) | 举报| 收藏