I want some Moore

Blog about stuff and things and stuff...
mostly about SQL server and .Net
posts - 161, comments - 1491, trackbacks - 33

My Links

SQLTeam.com Links

News

Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer. I'm also a MCP and MCTS for SQL Server. 
Welcome to my blog.

Search this Blog
 

My Blog Feed via Email


Get your Google PageRank
Users Online: who's online

Article Categories

Archives

Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

Column values Concat the SQL Server 2005 way

Here's an interesting way of contencating values in one column. It makes use of the new XML capabilities.

use master

select column_name as col1 FROM INFORMATION_SCHEMA.Columns WHERE table_name = 'spt_values'

select (select column_name as col1 FROM INFORMATION_SCHEMA.Columns WHERE table_name = 'spt_values' for xml raw, elements, type).query(' for $col1 in (row/col1) return concat($col1, ",")')

Order can be forced by using

       'for $col1 in (row/col1)
        order by $col1 ascending
        return concat($col1, ",")'

For descending order change ascending to descending.

Print | posted on Friday, June 02, 2006 11:47 PM

Feedback

# re: Column values Concat the SQL Server 2005 way

Well this was featured on
"the WHERE clause" SQL Server podcast on SSWUG.ORG
here
http://sswug.org/sswugradio/pdetails.asp?pid=112

seems that Chuck Boyce (http://chuckboyce.blogspot.com) likes this :))

thanx Chuck!
6/7/2006 6:06 PM | Mladen

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 6 and 2 and type the answer here:

Powered by: