Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends, i have requirement in sqlserver, Here problem is


ID -----------Name -------------salary (like that only)

1 ----------- ram ------------ 20000

1 ----------- sdfsdf------------ 2000000

2 ----------- ravi------------ 220000

2 ----------- sdfsdf------------ 555500


I want to below like that:

ID-----------Name1 -------------salary1-------Name2------------salary2

1------------ ram---------------- 20000--------- sdfsdf------------2000000
2------------- ravi----------------- 220000------- sdfsdf-------------555500


Here colon is only for identification. please any help me...
Posted
Updated 19-Sep-13 18:49pm
v3
Comments
gvprabu 20-Sep-13 6:24am    
If ID 1 having 3 rows then what is your required output..?

I would try pivoting the table. Is this a query pull that is getting you that top data?

Heres a fellow with a great article on sql server tables and pivoting/unpivoting.

http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]
 
Share this answer
 
Comments
CH Guravaiah 20-Sep-13 0:49am    
no need rows to column and column to row. I want only two rows into one row and each cell should be one columns(like to all)
SQL
select  d.ID,d.Name,d.salary,da.Name,da.salary 
from Data as d
left join Data as da
on d.ID = da.id
where d.Name in ('ram','ravi')
and da.Name = 'sdfsdf'
 
Share this answer
 
Comments
gvprabu 20-Sep-13 6:22am    
Are you checked with any sample values?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900