DCSIMG
TSQL: Concatenate Column from Multiple Rows into String - Adlai Maschiach

Adlai Maschiach

" You have to show in order to be seen "

News

Favorite Links

news

CardSpace

Books

Other InfoCards Proj

Virtual Earth

WSS / Sharepoint

SOA , Biztalk & ESB

CLR / .NET

TSQL: Concatenate Column from Multiple Rows into String

Ok , So I had a problem related to concatenation of a single Column into one ( same ) column when using GROUP BY .
The Problem came from a Reporting Services perspective and there might be other solutions ( like coding in VB.NET in the report )

I have found a very nice samples :

Option 1:

use Northwind

declare @CategoryList varchar(1000)
set @CategoryList =''
select @CategoryList = @CategoryList + ' , ' + CategoryName from Categories

select 'Results = ' + @CategoryList

Option 2:

use Northwind

declare @CategoryList varchar(1000)
select @CategoryList = coalesce(@CategoryList + ', ', '') + CategoryName from Categories

select 'Results = ' + @CategoryList

In the end I used option 2 as part of a UserDefiendFunction .

The manipulation was that the of the “GROUP BY” was sent to the UDF to use in it’s select “where” , so it could return the filtered row concatenated. And that UDF was called as part of the grand SELECT.

NOTE: this is a developer solution , a DBA might have a better solution ;)

Comments

Bharat said:

I think bgnilgog started and took off with people just writing about their personal lives, and it is later in the evolution that we see a lot more specialization.  It doesn't make sense to me to want to kill off personal blogs altogether.

# February 28, 2012 2:11 PM

Fullerton said:

What's up, all the time i used to check webpage posts here early in the daylight, because i like to find out more and more.

# July 22, 2012 7:33 AM

nipreinee said:

I'd need to check with you here. Which just isn't some thing I in most cases do! I delight in reading a post that can make persons think. Also, thanks for allowing me to comment!

[url=throwbacknfljerseys.beep.com]Throwback NFL Jerseys[/url]

nfljerseys2012.joomla-host.org

# January 15, 2013 3:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: