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
Explain what is the difference between a local and a global temporary table?
Explain the dirty pages?
How to read data in a table with "select" statements?
What is attribute hierarchy? : sql server analysis services, ssas
What is a linked server in sql server?
When you use @@error and try-catch?
Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?
How to insert multiple rows with a subquery?
Are there issues when exporting SSRS reports into Microsoft Excel? When my users are trying to export a SSRS report into Microsoft Excel, one or two columns in the report appear to merge together. Why might this be?
What are the types of normalization?
How to create new tables with "select ... Into" statements in ms sql server?
what are defaults? : Sql server database administration
What extended events?
Can we add an identity column to decimal datatype?
Describe the left outer join & right outer join. : sql server database administration