Archives / 2011 / December
  • Retrieving position() value of node by using XQuery alone

    You can only use the position() function within an xquery predicate and can't use it to return the position value of the node itself, which is a shame, but a couple of good workarounds have been published. However I had a requirement (don't ask why!) to return the position() of the node as a value within the xml itself.

    My requirement was to return an existing xml structure but to also include the position of a particular node as an additional attribute of that node. My other goal was to keep …

  • FOR XML PATH using node tests in column aliases

    I've used SQL to generate countless blobs of xml over the years and one feature that I have come to rely heavily upon is the ability to easily build complex xml structures by using column aliases in conjunction with the FOR XML PATH clause in your query. Not only do they allow for speedy creation, they also make the query very readable and it doesn't take long to be able to visualize the xml structure just by looking at the query itself. In conjunction with this, there are a number of node …