Retrieving XML Data from SQL Server 2000 via SELECT...FOR XML

After covering the XML features included with SQL Server 2005, discussing SELECT ... FOR XML queries is somewhat anticlimactic. I’ve included the information here for developers who are still using SQL Server 2000 in their applications and therefore can’t use SQL Server 2005’s XML features.

Executing a SELECT ... FOR XML Query in SQL Server Query Analyzer

The simplest way to execute such a query and examine the results is to execute the query in SQL Server Query Analyzer. Let’s take a simple query that retrieves the values of the CustomerID and CompanyName columns for the first two rows in the Customers table:

SELECT TOP 2 CustomerID, CompanyName FROM Customers

And then let’s append the ...

Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.