Need some help converting from access TRANSFORM COUNT/PIVOT to SQL SERVER and here's the sql from access :
TRANSFORM Count(tmpTbl.TC) AS CountOfTC
SELECT tmpTbl.SID, tmpTbl.CSID, tmpTbl.M,WoOr.QCL
FROM tmpTbl INNER JOIN WoOr ON tmpTbl.WO = WoOr.WO
WHERE (((tmpTbl.IsSelected)=True))
GROUP BY tmpTbl.SID, tmpTbl.CSID, tmpTbl.M,WoOr.QCL
PIVOT tmpTbl.TN;
OUTPUT:
SID | CSID | M | QCL | EPA 1 | EPA 2 |
-----------------------------------------|
1 | A |GW | IV | 3 | |
2 | B |GW | IV | | 4 |
------------------------------------------
WHere there are 3 EPA 1
count found and 4 EPA 2
count found IN tmpTbl Table.
Thank YOU in ADVANCE!
SQL Server doesn't use the TRANSFORM keyword along with PIVOT to convert the rows of data into columns. The basic syntax for a PIVOT will be using the sample from MSDN:
Once you understand where all of the pieces from your existing Access query will go in the SQL Server pivot, the syntax is easy to write. Your current query will be the following in SQL Server:
If you have unknown values, then you will want to use dynamic SQL to get the result: