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 / senthil kumar murugan

;WITH ABC (no, name) AS
(
SELECT 1, CAST('' AS VARCHAR(8000))
UNION ALL
SELECT B.no + 1, B.name + A.name + ', '
FROM (
SELECT Row_Number() OVER (ORDER BY no) AS no, name FROM
emp1) A
INNER JOIN ABC B ON A.no = B.no
)
SELECT TOP 1 name FROM ABC ORDER BY no DESC

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?

517


How to connect Azure federated root database and apply federation in entity framework?

87


Tell me what do we need queues in sql service broker?

508


Name 3 ways to get an accurate count of the number of records in a table?

560


How do I find the port number for sql server?

497






How to execute a sql statement using odbc_exec()?

564


Explain the different types of joins?

558


What is the new security features added in sql server 2014? : sql server security

556


How can you find out how many rows returned in a cursor?

545


What are subqueries in sql server?

586


what exactly sql injuction.how to overcome.....

2034


What is checkpoint in sql server?

607


How can I know what locks are running on which resource?

492


Explain about analysis services?

569


how to overcome kernel isssues

1167