Logo Cari Aylık Ekstre StoreProcedure
declare @carkod varchar(50)
set @carkod='120.33.028';
select aylar,case
when id = 1 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 2 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 3 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 4 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 5 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 6 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 7 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 8 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 9 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 10 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 11 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 12 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
end as borc,
case
when id = 1 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 2 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 3 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 4 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 5 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 6 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 7 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 8 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 9 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 10 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 11 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 12 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
end as alacak,case
when id = 1 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 2 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 3 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 4 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 5 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 6 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 7 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 8 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 9 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 10 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 11 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
when id = 12 then (select ISNULL(CONVERT(DECIMAL(16,2),SUM(BORC -ALACAK)),0) from V_CariEkstre where CARİ_KODU=@carkod and TARİH>='2017-01-01' and TARİH< ='2018-01-31')
end as bakiye
from tbl_aylar