Posts Tagged “XML”

Passing a list of values into a stored procedure with XML

Imagine you have a list of unrelated items in your .NET application, and you need SQL Server to do something for each one. For example: A customer has a shopping cart containing a list of 10 product IDs. The shopping cart is stored in ASP.NET session memory on the web server. How can you retrieve [...]

Read more »

More nested XML with SQL Server: n-level tree recursion

During my foray into XML SQL queries this week, I was presented with another challenge. Instead of getting just the immediate children of a category, I now needed to recursively select all children from a tree – to an unlimited depth. A Common Table Expression (CTE, aka WITH statement) can also be called recursively, but [...]

Read more »

Nested FOR XML results with SQL Server’s PATH mode

Today, while doing some work on a highly data (not object) driven .NET application, I needed a query output as XML from the application’s SQL Server 2005 database. I wanted: Nicely formatted and properly mapped XML (e.g. no <row> elements as found in FOR XML RAW mode) To be able to easily map columns to [...]

Read more »