Unlimited Web Space

Enjoy Unlimited web hosting

Sep 30, 2011

How to select multiple rows in one cell?

Suppose we have a table T1 as



C1     C2
1         a
2         s
3         d
4         f
5         g

Write a query as
DECLARE @C1_ALL NVARCHAR(MAX)
select @C1_ALL=coalesce(@C1_ALL + ', ','') + C1 from T1
select @C1_ALL

You will get the result as

C1_ALL
[1, 2, 3, 4, 5]

No comments:

Post a Comment