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

How to delete duplicate rows from table except one?

706


How to count rows with the count(*) function in ms sql server?

723


How do I find the size of a sql server database?

651


What is the maximum size per database for sql server express?

742


How to update values in a table with update statements in ms sql server?

737






Can sql servers link to other servers like oracle?

601


What are the different types of stored procedures?

793


What is the data type of time?

689


What is ssl in sql server?

747


What are the tables in sql?

788


What is bcnf normalization form?

847


Do you know what is sql service broker?

717


What is a collation?

808


What is the security principal at the server level that represents your session?

780


what is the difference between them (ethernet networks and token ring networks)? : Sql server database administration

702