SQL FOR XML - Outputting data as Elements or as Attributes SQL FOR XML - Outputting data as Elements or as Attributes xml xml

SQL FOR XML - Outputting data as Elements or as Attributes


Use @ to create attributes.

select SerialNo as "@id",       PartNo as "activeState/@partNumber",       convert(varchar(8), getdate(), 112) as "activeState/@shipmentDate"from Productswhere SerialNo = @SerialNofor xml path('product')