If you want to change the display to include the year, you may need to go to dynamic SQL.
FYI, you can use DATENAME() to simplify getting the month name:
datename( month, Invoice.[Date] )
You can then concatenate the year to that, but again to get this in the pivot you will have to use dynamic SQL approach. Please read here:
Dynamic Pivot Procedure for SQL Server - http:A_653.html
Main Topics
Browse All Topics





by: aneeshattingalPosted on 2009-11-05 at 09:11:40ID: 25751640
SELECT * h],[April] , t], ember],[De cember]
FROM(
SELECT
CASE MONTH(Invoice.[Date])
WHEN 1 THEN 'January'
WHEN 2 THEN 'February'
WHEN 3 THEN 'March'
WHEN 4 THEN 'April'
WHEN 5 THEN 'May'
WHEN 6 THEN 'June'
WHEN 7 THEN 'July'
WHEN 8 THEN 'August'
WHEN 9 THEN 'September'
WHEN 10 THEN 'October'
WHEN 11 THEN 'November'
WHEN 12 THEN 'December'
END AS [Month],
Invoice.InvoiceNo [InvoiceNo],
InvoiceLine.Amount [Amount],
Project.Number [Number]
FROM Invoice
INNER JOIN InvoiceLine ON Invoice.InvoiceId = InvoiceLine.InvoiceId
LEFT OUTER JOIN Project ON Invoice.ProjectId = Project.ProjectId
WHERE Invoice.[Date] >=DATEADD(month, DATEDIFF(month, '', getdate() ) , '')
) InvoiceLine
PIVOT
(
SUM(InvoiceLine.Amount)
FOR [Month] IN (
[January],[February],[Marc
[May],[June],[July],[Augus
[September],[October],[Nov
)
) AS PivotTable
ORDER BY [Number] DESC