Alex Rivera | Logout

Concat all column values in sql

Asked 2009-06-09T14:45:08.020
31

How to concat all column values from differenct rows returned from a sql query into one value? This is an example:

a query returns:

FOO
------
RES1

RES2

RES3

now I want to have a result like the following one:

FOOCONCAT
-----
RES1RES2RES3

Are there any ways to do this in sql?

Edit
Report

1 Answer

3

Assuming that it's one column with multiple values, this approach works for MS SQL Server (I can't speak for other systems).

declare @result varchar(max)
set @result = ''

select @result = @result + RES
from (query goes here)
answered 2009-06-09T15:01:14.663

Your Answer