Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have emp table as follows

Empid Empname Month Salary

1 A 1 3000
2 B 2 5000
3 C 3 8000
4 D 4 9000
5 E 5 7000


from the above i want the output as follows


Empid Empname 1 2 3 4 5

1 A 3000 5000 8000 9000 7000


from getting a above output how to write the query in sql server

What I have tried:

i have emp table as follows

Empid Empname Month Salary

1 A 1 3000
2 B 2 5000
3 C 3 8000
4 D 4 9000
5 E 5 7000


from the above i want the output as follows


Empid Empname 1 2 3 4 5

1 A 3000 5000 8000 9000 7000


from getting a above output how to write the query in sql server
Posted
Updated 17-Mar-17 23:47pm
Comments
Peter Leow 18-Mar-17 6:56am    
You output makes no sense. What do you want to achieve?

1 solution

You use a PIVOT query: Using PIVOT and UNPIVOT[^]
 
Share this answer
 

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