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

Community
  • 1
  • 1
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
  • This will help you.. http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-ms-sql-server-2005 – manurajhada May 24 '12 at 07:05
  • This is my preferred solution. It avoids errors when special characters are encountered http://stackoverflow.com/questions/5031204/does-t-sql-have-an-aggregate-function-to-concatenate-strings/5031297#5031297 – GarethD May 24 '12 at 07:56

1 Answers1

0
declare @var1 varchar(200)
SELECT @var1 = COALESCE(@var1 + ', ', '') +  Col2 from #table1 where Col1 = 'val1'
Select @var1
AmmarR
  • 248
  • 1
  • 11