Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 data of two rows in one row

Author  Topic 

guptaalok12
Starting Member

5 Posts

Posted - 2008-09-23 : 04:23:25
Emp
-----
ID Name
1 x
1 P
2 y
2 Q
3 W

Emp_Data

Id Name-1 Name-2
1 x P
2 y Q
3 w


above is my tables (Emp ),And the I want the Resulting Data in the (Emp_Data) format.is this possible Pls Help........Thanks in advance-----

alokgupta

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-23 : 04:53:43
[code]SELECT t.ID,
MAX(CASE WHEN t.Seq=1 THEN t.Name ELSE NULL END) AS Name_1,
MAX(CASE WHEN t.Seq=2 THEN t.Name ELSE NULL END) AS Name_2
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ID Order BY Name) AS Seq,* FROM Emp)t
GROUP BY t.ID[/code]
Go to Top of Page
   

- Advertisement -