I have this query:
select MONTH(x.status_date) m
, YEAR(x.status_date) y
from [XREF_WET_MASTER] x
join F_ACCESSION_DAILY f
on x.accession_id=f.accession_id
pivot (count(*) for f.REQUISITION_TYPE in ([req1],[req2],[req3])
) as CountofThatTypeofReq
and i am getting this error:
Incorrect syntax near ‘*’.
on the count(*) line
here are the expected results:
+---+------+------+------+------+
| m | y | req1 | req2 | req3 |
+---+------+------+------+------+
| 1 | 2010 | 34 | 3 | 6 |
| 2 | 2010 | 56 | 6 | 0 |
| 3 | 2010 | 5 | 33 | 4 |
+---+------+------+------+------+
I would be most grateful for any guidance on this pivot!
Instead of
count(*), you should be able to use something like the following: