Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
USE AdventureWorks2014;
SELECT *
FROM(
SELECT
VendorID, EmployeeID
FROM Purchasing.PurchaseOrderHeader
) AS PUR
PIVOT
(
COUNT(EmployeeID)
FOR EmployeeID IN ("250", "251", "256", "257", "260")
) AS PVT


What I have tried:

I'm not sure what to try as I'm very new to SQL.
Posted
Updated 2-May-19 2:47am

You should really read the web pages where you found your sample code.
SQL Aliases[^]

PIVOT and UNPIVOT in Sql Server | SqlHints.com[^]
Using PIVOT and UNPIVOT[^]
 
Share this answer
 
I want to add an extend to this question.
Let's say there is a table which will map the column names with actual names eg. in this case.

250 | emp1 |
251 | emp2 |
251 | Johny |
252 | Harry | and so on.

And the column names should be (emp1,emp2,John,...) and not (250,251,252,....).

Is there an elegant solution for this?
 
Share this answer
 
Comments
Patrice T 2-May-19 9:43am    
This is not a solution. Ask a new question with your problem and delete this.
https://www.codeproject.com/Questions/ask.aspx[^]

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