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
List down some advantages of sql stored procedure?
What is blocking and how would you troubleshoot it? : sql server database administration
What will be the maximum number of index per table?
What is difference between rownum and row_number?
What are the restrictions that views have to follow? : SQL Server Architecture
How to encrypt Strored Procedure in SQL SERVER?
what is bit datatype and what's the information that can be stored inside a bit column? : Sql server database administration
What is the maximum size per database for sql server express?
To automatically record the time on which the data was modified in a table, which data type should you choose for the column?
Can we use where clause in union?
What are differences in between sql server 2012 and sql server 2016?
Name three of the features managed by the surface area configuration tool? : sql server security
Can we write a distributed query and get some data which is located on other server and oracle database?
What is apply operator in sql?
How to check what was the last restore transaction LSN in Log shipping or Mirroring? when we don't have a Monitor or witness server.