I have the following query.
declare @column_names varchar(1000)
declare @result varchar(1000)
set @column_names='id,firstname,lastname,age,city,country'
set @result=''
select @result=@result+@column_names +','+from studenttable where id='1'
But this query returns id,firstname,lastname,age,city,country as result
and not like 1,john,j,21,newyork,us.
How to change query so that @result will contain actual entries in comma-separated form?
Please reply. Thanks.