|
There are probably a ton of uses for combining I'll start off with a snippet of a larger script. This snippet concatenates the index columns into a single field.
(comments are locked)
|
|
Reporting is the obvious answer. I also use it for providing a dynamic pivot. Actually, I use it remarkably regularly, and don't really think about the specific cases. But actually, you should change the way you use it. You'll notice that if you have an ampersand (or > or <) in your string, that this gets "HTMLEncoded" into The way to get around this is to do it slightly differently. Like this:
Like this:
....which I've blogged about at http://sqlblog.com/blogs/rob_farley/archive/2010/04/15/handling-special-characters-with-for-xml-path.aspx I like it. I would prefer to use the method that you just demonstrated rather than the text. I have noticed that on other scripts and have found other viable solutions. I figured for this script it wasn't necessary since the concatenation is on column names.
Apr 15 '10 at 02:01 AM
CirqueDeSQLeil
Using text() is just the same as using [*] or having no column name (as I've done). But even if you do, you still lose the special characters. Using root, type and .value will handle that for you though.
Apr 15 '10 at 05:12 AM
Rob Farley
Thanks a lot. Great stuff.
Apr 15 '10 at 03:31 PM
CirqueDeSQLeil
Ah - I should change it... you don't actually need the ROOT, because you can use '.' as the first argument in value...
Apr 15 '10 at 09:57 PM
Rob Farley
(comments are locked)
|
|
I think the vast majority of the use cases will be for string contatentation very similar to what you have done. I have frequently used it to turn attributes stored in a many-to-one relationship with the entity into a single string for display or use in reports. I frequently turn those things into views to make them easier to query while still maintaining the base data in a normalized form. I won't provide a code snippet, because Jeff Moden has already done it better than I could. His article at Thanks for pointing out Jeff's article.
Apr 15 '10 at 02:02 AM
CirqueDeSQLeil
(comments are locked)
|

