SELECT
tw_Symbol as [Symbol],
tw_Nazwa as [Nazwa],
sum(ob_IloscMag * ob_Znak) as [ROK],
sum(case when month(dok_datawyst)=1 then (ob_IloscMag * ob_Znak) end) as ,
sum(case when month(dok_datawyst)=2 then (ob_IloscMag * ob_Znak) end) as [II],
sum(case when month(dok_datawyst)=3 then (ob_IloscMag * ob_Znak) end) as [III],
sum(case when month(dok_datawyst)=4 then (ob_IloscMag * ob_Znak) end) as [IV],
sum(case when month(dok_datawyst)=5 then (ob_IloscMag * ob_Znak) end) as [V],
sum(case when month(dok_datawyst)=6 then (ob_IloscMag * ob_Znak) end) as [VI],
sum(case when month(dok_datawyst)=7 then (ob_IloscMag * ob_Znak) end) as [VII],
sum(case when month(dok_datawyst)=8 then (ob_IloscMag * ob_Znak) end) as [VIII],
sum(case when month(dok_datawyst)=9 then (ob_IloscMag * ob_Znak) end) as [IX],
sum(case when month(dok_datawyst)=10 then (ob_IloscMag * ob_Znak) end) as [X],
sum(case when month(dok_datawyst)=11 then (ob_IloscMag * ob_Znak) end) as [XI],
sum(case when month(dok_datawyst)=12 then (ob_IloscMag * ob_Znak) end) as [XII]
FROM vwZstSprzWgKhnt LEFT JOIN tw__Towar ON ob_TowId = tw_Id
WHERE(YEAR (dok_DataWyst) ={LI:2009#2009#2010#2010#2011#2011#2012#2012#2013#2013#2014#2014#2015#2015#2016#2016#2017#2017#2018#2018#2019#2019#2020#2020#2021#2021#:Wybierz rok:2021})
AND (dok_Typ IN({CHL:FS - Faktura Sprzedaży#2#KFS - Korekta Faktury Sprzedaży#6#PA - Paragon#21#ZD - Zwrot Detaliczny#14#:Typ dokumentu:2,6,14,21:(wszystkie dokumenty sprzedaży)}))
AND (dok_Status <> 2)
AND (tw_Rodzaj IN({CHL:TOWAR#1#USŁUGI#2#OPAKOWANIA#4#KOMPLETY#8#:Towar czy Usługa:1:( Towary )}))
GROUP by tw_Symbol, tw_Nazwa
ORDER by tw_Symbol