I have the below which gives me SalesExVAT
, by BranchNo
and by FiscalWeek
there is only 1 record per branch for each week:
Select
sa.BranchNo
,sa.FiscalWeek
,sa.SalesExVAT
From
dbo.SalesAggregateWeek sa
Where
sa.FiscalYear = 2016
I wanted to display this in a Pivoted Format
I have tried the below,
Select
MyData.BranchNo
From
(Select
sa.BranchNo
,sa.FiscalWeek
,sa.SalesExVAT
From
dbo.SalesAggregateWeek sa
Where
sa.FiscalYear = 2016) MyData
Pivot
( sum(MyData.salesexvat)
For
MyData.FiscalWeek In (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52) )
The desired out come would have the FiscalWeek
as the headers along the top, the BranchNo
displayed down the left, and SalesExVAT
info as the data.
Any ideas on what I must do to correct my code are welcome as I've not used PIVOT yet.