![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Here is one method. You can use COALESCE on all columns if you want to replace NULLs with 0 (as it was done for December). SELECT year_nbr, [1] AS jan, [2] AS feb, [3] AS mar, [4] AS apr, [5] AS may, [6] AS jun, [7] AS jul, [8] AS aug, [9] AS sep, [10] AS oct, [11] AS nov, COALESCE([12], 0) AS dec FROM ( SELECT YEAR([date]) AS year_nbr, MONTH([date]) AS month_nbr, quantity FROM Foo ) AS F PIVOT (SUM(quantity) FOR month_nbr IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12])) AS P; |
#4
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |