there is a table having two columns no and name
and the data is
1 A
2 B
3 C

write a query that will result a horizontal output
A,B,C

Answer Posted / utsav

declare @tst varchar(max)
set @tst=''
select @tst=@tst+col+',' from table
select @tst

there is a twist, if col contains any null value then this
query will return null. use isnull(col,'') in that case

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of dml?

736


Explain for xml explicit mode?

737


How to return the second 5 rows in ms sql server?

790


What do you understand by hotfixes and patches in sql server?

690


What are system databases in ms sql server?

699






explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration

696


How to test subquery results with the exists operator?

747


What are different types of replication in sql server?

750


Why should we go for stored procedures? Why not direct queries?

749


What are null values in ms sql server?

756


What is cube dimension? : sql server analysis services, ssas

713


what's the difference between a primary key and a unique key? : Sql server database administration

686


can a database be shrunk with users active? : Sql server administration

759


What is service broker? : sql server database administration

743


What are trace files?

707