Column data in to single row with comma seperated

Wednesday, 29 February 2012

Column data in to single row with comma seperated


Below SQl statement is used for convert single column data in a single row.

declare @testdata varchar(8000)
set @testdata=''

select @testdata=@testdata+NAME+', ' from User where ID in('1','2','3','4','5')
print @testdata

select substring(@testdata,0,len(@testdata))


In above User is a table
NAME is column of user which data will be manuplate in row
ID is column of user
Actual data format was:





After query the data format will be:


No comments:

Post a comment