0

Possible Duplicate:
Simulating group_concat MySQL function in MS SQL Server 2005?
Does T-SQL have an aggregate function to concatenate strings?
SQL group_concat function in SQL Server

I've tabular structure like this

    Table1
Col1     Col2

val1     text1

val1     text2

val1     text3

val1     text4

val1     text5

Now i want the output using a simple sql statement(No procedure No function) in this form like this.

statement like

select col2 where col1 = 'val1'

output like

text1,text2,text3,text4,text5

2

1 Answer 1

0
declare @var1 varchar(200)
SELECT @var1 = COALESCE(@var1 + ', ', '') +  Col2 from #table1 where Col1 = 'val1'
Select @var1
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.