Created
August 26, 2009 17:46
-
-
Save nathany/175670 to your computer and use it in GitHub Desktop.
pivot table example in SQL Server 2005
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select PT.FacID, f1.FacName, [1] as QtyAlloc, [-1] as QtyUsed, [1] + [-1] as QtyRemain | |
from | |
( | |
select f1.FacID, sign(f1.Quantity) as Sgn, f1.Quantity | |
from FacCredits f1 | |
) as q1 | |
pivot | |
( | |
sum(q1.Quantity) | |
for q1.Sgn in ([1], [-1]) | |
) as PT | |
left join Facilitators f1 on PT.FacID = f1.FacID | |
order by [1] + [-1] desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment