i want have the layout of pivot table with on top period YYYYMM in dynamic table. show sum of consumption per month show 1 year. but when i tried put the data (period (201801,201802...)) don't work with PERIOD table on dynamic ?!!
i don't know if im doing something wrong on the report ...can anyone help withit ?
The query without be in dynamic and work but when I tried to change to dynamic I can't make it work.
DECLARE @ColumnNames NVARCHAR(MAX) = ' '
DECLARE @SQL NVARCHAR (MAX) = ' '
SELECT   @ColumnNames += QUOTENAME(Period) + ','
FROM     [STOKVIS LIVE].[dbo].[SR_CONS_Consumption1year]
SET @ColumnNames = LEFT (@ColumnNames,LEN(@ColumnNames)-1) 
SET @SQL = 
SELECT [No_] ,[Group],[Lakeview],[Name],[class.],[Stock], [Period]
FROM [STOKVIS LIVE].[dbo].[SR_CONS_Consumption1year]
PIVOT (
    SUM ([Qty])
    FOR [Period]
    IN( ' + @ColumnNames +   ')
    )
    as pivortable
 
    