Andrew Pfeiffer (3/26/2008)
Mike C (3/26/2008)
For readability purposes I'd probably go with something like this:
SELECT x.value('Name[1]', 'VARCHAR(20)')
FROM @x.nodes('/Employees/Employee') e(x);
I like this method. It is actually faster and uses less resources as it applies the XPathFilter.
Thanks for the tip =)
No problem 🙂 I was at a presentation that Michael Rys gave a while back and here are some more of his tips for making your XQuery as efficient as possible:
- Don't use the ".." axis if you can avoid it.
- Don't use "//" with the wildcard "*" in the middle of a path expression.
- Use [i]n[/i] predicate filter to give the optimizer cardinality hints whenever possible (e.g., "[1]"). This forces the optimizer to make better decisions about which operators to use.
He actually covered about 10 more things, but I can't remember them all off the top of my head. Some were for very specific situations, and probably fairly uncommon.