Click here to Skip to main content
15,885,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use sqlserver 2012 Express

I have this select

select C.COMPUTER_NAME, A.PART_NAME
from Projects.PARTS_ON_COMPUTERS P
left join Projects.COMPUTERS C ON C.Id= P.COMPUTER
LEFT JOIN Projects.COMPUTER_PARTS A ON A.Id= P.PART

gives mes results

computer_Name part_name
--------------------------------------------
pc1 hard 200g
pc1 display card
pc1 network card
pc2 hard 500g
pc2 display card

but I need the results to be

pc1 hard 200g display card network card
pc2 hard 500g display card


please help
Posted
Updated 20-Dec-15 3:25am
v2

1 solution

I suspect you don't really need to this, and the transformation would be better done in .the code.
But if you *really* need to do it in SQL, look at PIVOT and UNPIVOT.

Oh, and take a look over on the right of the page at 'Related Questions'...
 
Share this answer
 
v3
Comments
samerselo 20-Dec-15 12:35pm    
I need to do it by sql statement bcz it will populate gridview in asp.net page
but my knowledge of pivot is 0%

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