Example: Retrieving Product Model Information as XML

The following query returns product model information. mode is specified in the clause. SQ

The following query returns product model information.

mode is specified in the

clause.

This is the partial result:

XML

You can retrieve element-centric XML by specifying the

directive.

This is the result:

XML

RAW
FOR XML
ELEMENTS
USE
AdventureWorks2022;
GO
SELECT
ProductModelID,
Name
FROM
Production.ProductModel
WHERE
ProductModelID
IN (122, 119)
FOR
XML
RAW
;
GO
<row
ProductModelID
=
"122"
Name
=
"All-Purpose Bike Stand"
/>
<row
ProductModelID
=
"119"
Name
=
"Bike Wash"
/>
USE
AdventureWorks2022;
GO
SELECT
ProductModelID,
Name
FROM
Production.ProductModel
WHERE
ProductModelID
IN (122, 119)
FOR
XML
RAW
, ELEMENTS;
GO
<row>
<ProductModelID>
122
</ProductModelID>