question

mostafa avatar image
mostafa asked

how i can convert rows to column in sql server 2008?

i have 2 table (Nationality,Employee) the column in table 1 is (Natonality_Id,Nationality_Name) Table 2 (Employee_Id,Employee_Name,Nationality_Id) when i write this query

select Nationality_Name,Employee_Name                    
from Employee join Nationality                    
on Employee.Nationality_Id=Nationality_Id                    

the result is

Employee_Name   Nationality_Name                    
Mohamed         Egypt                    
Mostafa         Egypt                    
Jone            USA                    
Mena            USA                    

but i want the result is

Egypt           USA                    
Mohamed         Jone                    
Mostafa         Mena                    

i want the code can give me this result please help me Mostafa Elmasry

sql-server-2008pivot
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
RickD avatar image
RickD answered

Use PIVOT, there are plently of examples around the internet.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.