June 25, 2012 at 5:56 am
set statistics io on
set nocount on
declare @datefrom varchar(100)
declare @dateto varchar(100)
set @datefrom='01/05/2012'
set @dateto='15/05/2012'
set @datefrom=dbo.getSqlFormatDate (isnull(@datefrom,'01/01/1900'))
set @dateto = dbo.getSqlFormatDate (isnull(@dateto,'01/01/1900'))
set transaction isolation level read uncommitted
select distinct likp.VBELN as delivery,vbak.VBELN as sales_document,vbrp.VBELN as bill_no,
vbrk.FKDAT as invoice_date,AUDAT as sales_order_date,likp.ZZCND as delivery_date,likp.PODAT as POD_date,
submission_date as sub_date,vbak.ZZP01 as payment_rule,vbrk.ZTERM as payment_term,
(case
when vbrk.ZTERM ='Z003' and vbak.ZZP01='A' then DATEADD(DD,1,likp.ZZCND)
when vbrk.ZTERM ='Z003' and vbak.ZZP01='B' then DATEADD(DD,1,AUDAT)
when vbrk.ZTERM ='Z003' and vbak.ZZP01='C' then DATEADD(DD,1,vbrk.FKDAT)
when vbrk.ZTERM ='Z003' and vbak.ZZP01='E' then DATEADD(DD,1,likp.PODAT)
when vbrk.ZTERM ='Z003' and vbak.ZZP01=' ' then DATEADD(DD,1,vbrk.FKDAT)
when vbrk.ZTERM ='Z003' and aa.pay_rule='D' then DATEADD(DD,1,aa.submission_date)
when vbrk.ZTERM ='Z004' and vbak.ZZP01='A' then DATEADD(DD,2,likp.ZZCND)
when vbrk.ZTERM ='Z004' and vbak.ZZP01='B' then DATEADD(DD,2,AUDAT)
when vbrk.ZTERM ='Z004' and vbak.ZZP01='C' then DATEADD(DD,2,vbrk.FKDAT)
when vbrk.ZTERM ='Z004' and vbak.ZZP01='E' then DATEADD(DD,2,likp.PODAT)
when vbrk.ZTERM ='Z004' and vbak.ZZP01=' ' then DATEADD(DD,2,vbrk.FKDAT)
when vbrk.ZTERM ='Z004' and aa.pay_rule='D' then DATEADD(DD,2,aa.submission_date)
when vbrk.ZTERM ='Z005' and vbak.ZZP01='A' then DATEADD(DD,3,likp.ZZCND)
when vbrk.ZTERM ='Z005' and vbak.ZZP01='B' then DATEADD(DD,3,AUDAT)
when vbrk.ZTERM ='Z005' and vbak.ZZP01='C' then DATEADD(DD,3,vbrk.FKDAT)
when vbrk.ZTERM ='Z005' and vbak.ZZP01='E' then DATEADD(DD,3,likp.PODAT)
when vbrk.ZTERM ='Z005' and vbak.ZZP01=' ' then DATEADD(DD,3,vbrk.FKDAT)
when vbrk.ZTERM ='Z005' and aa.pay_rule='D' then DATEADD(DD,3,aa.submission_date)
when vbrk.ZTERM ='Z006' and vbak.ZZP01='A' then DATEADD(DD,4,likp.ZZCND)
when vbrk.ZTERM ='Z006' and vbak.ZZP01='B' then DATEADD(DD,4,AUDAT)
when vbrk.ZTERM ='Z006' and vbak.ZZP01='C' then DATEADD(DD,4,vbrk.FKDAT)
when vbrk.ZTERM ='Z006' and vbak.ZZP01='E' then DATEADD(DD,4,likp.PODAT)
when vbrk.ZTERM ='Z006' and vbak.ZZP01=' ' then DATEADD(DD,4,vbrk.FKDAT)
when vbrk.ZTERM ='Z006' and aa.pay_rule='D' then DATEADD(DD,4,aa.submission_date)
when vbrk.ZTERM ='Z007' and vbak.ZZP01='A' then DATEADD(DD,5,likp.ZZCND)
when vbrk.ZTERM ='Z007' and vbak.ZZP01='B' then DATEADD(DD,5,AUDAT)
when vbrk.ZTERM ='Z007' and vbak.ZZP01='C' then DATEADD(DD,5,vbrk.FKDAT)
when vbrk.ZTERM ='Z007' and vbak.ZZP01='E' then DATEADD(DD,5,likp.PODAT)
when vbrk.ZTERM ='Z007' and vbak.ZZP01=' ' then DATEADD(DD,5,vbrk.FKDAT)
when vbrk.ZTERM ='Z007' and aa.pay_rule='D' then DATEADD(DD,5,aa.submission_date)
when vbrk.ZTERM ='Z008' and vbak.ZZP01='A' then DATEADD(DD,6,likp.ZZCND)
when vbrk.ZTERM ='Z008' and vbak.ZZP01='B' then DATEADD(DD,6,AUDAT)
when vbrk.ZTERM ='Z008' and vbak.ZZP01='C' then DATEADD(DD,6,vbrk.FKDAT)
when vbrk.ZTERM ='Z008' and vbak.ZZP01='E' then DATEADD(DD,6,likp.PODAT)
when vbrk.ZTERM ='Z008' and vbak.ZZP01=' ' then DATEADD(DD,6,vbrk.FKDAT)
when vbrk.ZTERM ='Z008' and aa.pay_rule='D' then DATEADD(DD,6,aa.submission_date)
when vbrk.ZTERM ='Z009' and vbak.ZZP01='A' then DATEADD(DD,7,likp.ZZCND)
when vbrk.ZTERM ='Z009' and vbak.ZZP01='B' then DATEADD(DD,7,AUDAT)
when vbrk.ZTERM ='Z009' and vbak.ZZP01='C' then DATEADD(DD,7,vbrk.FKDAT)
when vbrk.ZTERM ='Z009' and vbak.ZZP01='E' then DATEADD(DD,7,likp.PODAT)
when vbrk.ZTERM ='Z009' and vbak.ZZP01=' ' then DATEADD(DD,7,vbrk.FKDAT)
when vbrk.ZTERM ='Z009' and aa.pay_rule='D' then DATEADD(DD,7,aa.submission_date)
when vbrk.ZTERM ='Z010' and vbak.ZZP01='A' then DATEADD(DD,8,likp.ZZCND)
when vbrk.ZTERM ='Z010' and vbak.ZZP01='B' then DATEADD(DD,8,AUDAT)
when vbrk.ZTERM ='Z010' and vbak.ZZP01='C' then DATEADD(DD,8,vbrk.FKDAT)
when vbrk.ZTERM ='Z010' and vbak.ZZP01='E' then DATEADD(DD,8,likp.PODAT)
when vbrk.ZTERM ='Z010' and vbak.ZZP01=' ' then DATEADD(DD,8,vbrk.FKDAT)
when vbrk.ZTERM ='Z010' and aa.pay_rule='D' then DATEADD(DD,8,aa.submission_date)
when vbrk.ZTERM ='Z011' and vbak.ZZP01='A' then DATEADD(DD,9,likp.ZZCND)
when vbrk.ZTERM ='Z011' and vbak.ZZP01='B' then DATEADD(DD,9,AUDAT)
when vbrk.ZTERM ='Z011' and vbak.ZZP01='C' then DATEADD(DD,9,vbrk.FKDAT)
when vbrk.ZTERM ='Z011' and vbak.ZZP01='E' then DATEADD(DD,9,likp.PODAT)
when vbrk.ZTERM ='Z011' and vbak.ZZP01=' ' then DATEADD(DD,9,vbrk.FKDAT)
when vbrk.ZTERM ='Z011' and aa.pay_rule='D' then DATEADD(DD,9,aa.submission_date)
when vbrk.ZTERM ='Z012' and vbak.ZZP01='A' then DATEADD(DD,10,likp.ZZCND)
when vbrk.ZTERM ='Z012' and vbak.ZZP01='B' then DATEADD(DD,10,AUDAT)
when vbrk.ZTERM ='Z012' and vbak.ZZP01='C' then DATEADD(DD,10,vbrk.FKDAT)
when vbrk.ZTERM ='Z012' and vbak.ZZP01='E' then DATEADD(DD,10,likp.PODAT)
when vbrk.ZTERM ='Z012' and vbak.ZZP01=' ' then DATEADD(DD,10,vbrk.FKDAT)
when vbrk.ZTERM ='Z012' and aa.pay_rule='D' then DATEADD(DD,10,aa.submission_date)
when vbrk.ZTERM ='Z013' and vbak.ZZP01='A' then DATEADD(DD,12,likp.ZZCND)
when vbrk.ZTERM ='Z013' and vbak.ZZP01='B' then DATEADD(DD,12,AUDAT)
when vbrk.ZTERM ='Z013' and vbak.ZZP01='C' then DATEADD(DD,12,vbrk.FKDAT)
when vbrk.ZTERM ='Z013' and vbak.ZZP01='E' then DATEADD(DD,12,likp.PODAT)
when vbrk.ZTERM ='Z013' and vbak.ZZP01=' ' then DATEADD(DD,12,vbrk.FKDAT)
when vbrk.ZTERM ='Z013' and aa.pay_rule='D' then DATEADD(DD,12,aa.submission_date)
when vbrk.ZTERM ='Z014' and vbak.ZZP01='A' then DATEADD(DD,15,likp.ZZCND)
when vbrk.ZTERM ='Z014' and vbak.ZZP01='B' then DATEADD(DD,15,AUDAT)
when vbrk.ZTERM ='Z014' and vbak.ZZP01='C' then DATEADD(DD,15,vbrk.FKDAT)
when vbrk.ZTERM ='Z014' and vbak.ZZP01='E' then DATEADD(DD,15,likp.PODAT)
when vbrk.ZTERM ='Z014' and vbak.ZZP01=' ' then DATEADD(DD,15,vbrk.FKDAT)
when vbrk.ZTERM ='Z014' and aa.pay_rule='D' then DATEADD(DD,15,aa.submission_date)
when vbrk.ZTERM ='Z015' and vbak.ZZP01='A' then DATEADD(DD,20,likp.ZZCND)
when vbrk.ZTERM ='Z015' and vbak.ZZP01='B' then DATEADD(DD,20,AUDAT)
when vbrk.ZTERM ='Z015' and vbak.ZZP01='C' then DATEADD(DD,20,vbrk.FKDAT)
when vbrk.ZTERM ='Z015' and vbak.ZZP01='E' then DATEADD(DD,20,likp.PODAT)
when vbrk.ZTERM ='Z015' and vbak.ZZP01=' ' then DATEADD(DD,20,vbrk.FKDAT)
when vbrk.ZTERM ='Z015' and aa.pay_rule='D' then DATEADD(DD,20,aa.submission_date)
when vbrk.ZTERM ='Z016' and vbak.ZZP01='A' then DATEADD(DD,21,likp.ZZCND)
when vbrk.ZTERM ='Z016' and vbak.ZZP01='B' then DATEADD(DD,21,AUDAT)
when vbrk.ZTERM ='Z016' and vbak.ZZP01='C' then DATEADD(DD,21,vbrk.FKDAT)
when vbrk.ZTERM ='Z016' and vbak.ZZP01='E' then DATEADD(DD,21,likp.PODAT)
when vbrk.ZTERM ='Z016' and vbak.ZZP01=' ' then DATEADD(DD,21,vbrk.FKDAT)
when vbrk.ZTERM ='Z016' and aa.pay_rule='D' then DATEADD(DD,21,aa.submission_date)
when vbrk.ZTERM ='Z017' and vbak.ZZP01='A' then DATEADD(DD,24,likp.ZZCND)
when vbrk.ZTERM ='Z017' and vbak.ZZP01='B' then DATEADD(DD,24,AUDAT)
when vbrk.ZTERM ='Z017' and vbak.ZZP01='C' then DATEADD(DD,24,vbrk.FKDAT)
when vbrk.ZTERM ='Z017' and vbak.ZZP01='E' then DATEADD(DD,24,likp.PODAT)
when vbrk.ZTERM ='Z017' and vbak.ZZP01=' ' then DATEADD(DD,24,vbrk.FKDAT)
when vbrk.ZTERM ='Z017' and aa.pay_rule='D' then DATEADD(DD,24,aa.submission_date)
when vbrk.ZTERM ='Z018' and vbak.ZZP01='A' then DATEADD(DD,25,likp.ZZCND)
when vbrk.ZTERM ='Z018' and vbak.ZZP01='B' then DATEADD(DD,25,AUDAT)
when vbrk.ZTERM ='Z018' and vbak.ZZP01='C' then DATEADD(DD,25,vbrk.FKDAT)
when vbrk.ZTERM ='Z018' and vbak.ZZP01='E' then DATEADD(DD,25,likp.PODAT)
when vbrk.ZTERM ='Z018' and vbak.ZZP01=' ' then DATEADD(DD,25,vbrk.FKDAT)
when vbrk.ZTERM ='Z018' and aa.pay_rule='D' then DATEADD(DD,25,aa.submission_date)
when vbrk.ZTERM ='Z019' and vbak.ZZP01='A' then DATEADD(DD,30,likp.ZZCND)
when vbrk.ZTERM ='Z019' and vbak.ZZP01='B' then DATEADD(DD,30,AUDAT)
when vbrk.ZTERM ='Z019' and vbak.ZZP01='C' then DATEADD(DD,30,vbrk.FKDAT)
when vbrk.ZTERM ='Z019' and vbak.ZZP01='E' then DATEADD(DD,30,likp.PODAT)
when vbrk.ZTERM ='Z019' and vbak.ZZP01=' ' then DATEADD(DD,30,vbrk.FKDAT)
when vbrk.ZTERM ='Z019' and aa.pay_rule='D' then DATEADD(DD,30,aa.submission_date)
when vbrk.ZTERM ='Z020' and vbak.ZZP01='A' then DATEADD(DD,35,likp.ZZCND)
when vbrk.ZTERM ='Z020' and vbak.ZZP01='B' then DATEADD(DD,35,AUDAT)
when vbrk.ZTERM ='Z020' and vbak.ZZP01='C' then DATEADD(DD,35,vbrk.FKDAT)
when vbrk.ZTERM ='Z020' and vbak.ZZP01='E' then DATEADD(DD,35,likp.PODAT)
when vbrk.ZTERM ='Z020' and vbak.ZZP01=' ' then DATEADD(DD,35,vbrk.FKDAT)
when vbrk.ZTERM ='Z020' and aa.pay_rule='D' then DATEADD(DD,35,aa.submission_date)
when vbrk.ZTERM ='Z021' and vbak.ZZP01='A' then DATEADD(DD,40,likp.ZZCND)
when vbrk.ZTERM ='Z021' and vbak.ZZP01='B' then DATEADD(DD,40,AUDAT)
when vbrk.ZTERM ='Z021' and vbak.ZZP01='C' then DATEADD(DD,40,vbrk.FKDAT)
when vbrk.ZTERM ='Z021' and vbak.ZZP01='E' then DATEADD(DD,40,likp.PODAT)
when vbrk.ZTERM ='Z021' and vbak.ZZP01=' ' then DATEADD(DD,40,vbrk.FKDAT)
when vbrk.ZTERM ='Z021' and aa.pay_rule='D' then DATEADD(DD,40,aa.submission_date)
when vbrk.ZTERM ='Z022' and vbak.ZZP01='A'then DATEADD(DD,45,likp.ZZCND)
when vbrk.ZTERM ='Z022' and vbak.ZZP01='B' then DATEADD(DD,45,AUDAT)
when vbrk.ZTERM ='Z022' and vbak.ZZP01='C' then DATEADD(DD,45,vbrk.FKDAT)
when vbrk.ZTERM ='Z022' and vbak.ZZP01='E' then DATEADD(DD,45,likp.PODAT)
when vbrk.ZTERM ='Z022' and vbak.ZZP01=' ' then DATEADD(DD,45,vbrk.FKDAT)
when vbrk.ZTERM ='Z022' and aa.pay_rule='D' then DATEADD(DD,45,aa.submission_date)
when vbrk.ZTERM ='Z023' and vbak.ZZP01='A' then DATEADD(DD,60,likp.ZZCND)
when vbrk.ZTERM ='Z023' and vbak.ZZP01='B' then DATEADD(DD,60,AUDAT)
when vbrk.ZTERM ='Z023' and vbak.ZZP01='C' then DATEADD(DD,60,vbrk.FKDAT)
when vbrk.ZTERM ='Z023' and vbak.ZZP01='E' then DATEADD(DD,60,likp.PODAT)
when vbrk.ZTERM ='Z023' and vbak.ZZP01=' ' then DATEADD(DD,60,vbrk.FKDAT)
when vbrk.ZTERM ='Z023' and aa.pay_rule='D' then DATEADD(DD,60,aa.submission_date)
when vbrk.ZTERM ='Z024' and vbak.ZZP01='A' then DATEADD(DD,65,likp.ZZCND)
when vbrk.ZTERM ='Z024' and vbak.ZZP01='B' then DATEADD(DD,65,AUDAT)
when vbrk.ZTERM ='Z024' and vbak.ZZP01='C' then DATEADD(DD,65,vbrk.FKDAT)
when vbrk.ZTERM ='Z024' and vbak.ZZP01='E' then DATEADD(DD,65,likp.PODAT)
when vbrk.ZTERM ='Z024' and vbak.ZZP01=' ' then DATEADD(DD,65,vbrk.FKDAT)
when vbrk.ZTERM ='Z024' and aa.pay_rule='D' then DATEADD(DD,65,aa.submission_date)
when vbrk.ZTERM ='Z025' and vbak.ZZP01='A' then DATEADD(DD,70,likp.ZZCND)
when vbrk.ZTERM ='Z025' and vbak.ZZP01='B' then DATEADD(DD,70,AUDAT)
when vbrk.ZTERM ='Z025' and vbak.ZZP01='C' then DATEADD(DD,70,vbrk.FKDAT)
when vbrk.ZTERM ='Z025' and vbak.ZZP01='E' then DATEADD(DD,70,likp.PODAT)
when vbrk.ZTERM ='Z025' and vbak.ZZP01=' ' then DATEADD(DD,70,vbrk.FKDAT)
when vbrk.ZTERM ='Z025' and aa.pay_rule='D' then DATEADD(DD,70,aa.submission_date)
when vbrk.ZTERM ='Z026' and vbak.ZZP01='A' then DATEADD(DD,80,likp.ZZCND)
when vbrk.ZTERM ='Z026' and vbak.ZZP01='B' then DATEADD(DD,80,AUDAT)
when vbrk.ZTERM ='Z026' and vbak.ZZP01='C' then DATEADD(DD,80,vbrk.FKDAT)
when vbrk.ZTERM ='Z026' and vbak.ZZP01='E' then DATEADD(DD,80,likp.PODAT)
when vbrk.ZTERM ='Z026' and vbak.ZZP01=' ' then DATEADD(DD,80,vbrk.FKDAT)
when vbrk.ZTERM ='Z026' and aa.pay_rule='D' then DATEADD(DD,80,aa.submission_date)
when vbrk.ZTERM ='Z027' and vbak.ZZP01='A' then DATEADD(DD,90,likp.ZZCND)
when vbrk.ZTERM ='Z027' and vbak.ZZP01='B' then DATEADD(DD,90,AUDAT)
when vbrk.ZTERM ='Z027' and vbak.ZZP01='C' then DATEADD(DD,90,vbrk.FKDAT)
when vbrk.ZTERM ='Z027' and vbak.ZZP01='E' then DATEADD(DD,90,likp.PODAT)
when vbrk.ZTERM ='Z027' and vbak.ZZP01=' ' then DATEADD(DD,90,vbrk.FKDAT)
when vbrk.ZTERM ='Z027' and aa.pay_rule='D' then DATEADD(DD,90,aa.submission_date)
when vbrk.ZTERM ='Z028' and vbak.ZZP01='A' then DATEADD(DD,120,likp.ZZCND)
when vbrk.ZTERM ='Z028' and vbak.ZZP01='B' then DATEADD(DD,120,AUDAT)
when vbrk.ZTERM ='Z028' and vbak.ZZP01='C' then DATEADD(DD,120,vbrk.FKDAT)
when vbrk.ZTERM ='Z028' and vbak.ZZP01='E' then DATEADD(DD,120,likp.PODAT)
when vbrk.ZTERM ='Z028' and vbak.ZZP01=' ' then DATEADD(DD,120,vbrk.FKDAT)
when vbrk.ZTERM ='Z028' and aa.pay_rule='D' then DATEADD(DD,120,aa.submission_date)
else '1900-01-01 00:00:00.000'
end) as duedate
--into #temp
from DEP.dep.LIKP likp
inner join DEP.dep.LIPS lips on likp.VBELN=lips.VBELN and likp.MANDT=lips.MANDT
inner join DEP.dep.VBAK vbak on lips.VGBEL=vbak.VBELN and lips.MANDT=vbak.MANDT
inner join DEP.dep.VBKD vbkd on vbkd.VBELN= vbak.VBELN and vbkd.MANDT=vbak.MANDT
inner join DEP.dep.VBRP vbrp on vbrp.VGBEL=lips.VBELN and vbrp.MANDT=lips.MANDT AND lips.POSNR = vbrp.VGPOS
inner join DEP.dep.VBRK vbrk on vbrk.VBELN=vbrp.VBELN and vbrp.MANDT=vbrk.MANDT
inner join SAP_FactTable_GM p on p.VBELN=vbrp.VGBEL
inner join Fact_BestPaymaster bp on p.CustomerId=bp.CustomerId
left join (select zs.VBELN as bill_no,ZZIDAT as submission_date,ZZP01 as pay_rule
from DEP.dep.ZSD_TAB_VBRK zs
where zs.MANDT='800') aa on aa.bill_no=vbrp.VBELN
where likp.MANDT='800'
and PostingDate between @datefrom and @dateto
June 25, 2012 at 6:36 am
what is this and what do you want?
Note: kindly dont ask for your work help..
Regards
Durai Nagarajan
June 25, 2012 at 7:40 am
No problem:
select distinct likp.VBELN as delivery,vbak.VBELN as sales_document,vbrp.VBELN as bill_no,
vbrk.FKDAT as invoice_date,AUDAT as sales_order_date,likp.ZZCND as delivery_date,likp.PODAT as POD_date,
submission_date as sub_date,vbak.ZZP01 as payment_rule,vbrk.ZTERM as payment_term,
(case
when vbak.ZZP01 = 'A' then DATEADD(DD,x.DateDelta,likp.ZZCND)
when vbak.ZZP01 = 'B' then DATEADD(DD,x.DateDelta,AUDAT)
when vbak.ZZP01 = 'C' then DATEADD(DD,x.DateDelta,vbrk.FKDAT)
when vbak.ZZP01 = 'E' then DATEADD(DD,x.DateDelta,likp.PODAT)
when vbak.ZZP01 = ' ' then DATEADD(DD,x.DateDelta,vbrk.FKDAT)
when aa.pay_rule= 'D' then DATEADD(DD,x.DateDelta,aa.submission_date)
else '1900-01-01 00:00:00.000'
end) as duedate
--into #temp
from DEP.dep.LIKP likp
inner join DEP.dep.LIPS lips on likp.VBELN=lips.VBELN and likp.MANDT=lips.MANDT
inner join DEP.dep.VBAK vbak on lips.VGBEL=vbak.VBELN and lips.MANDT=vbak.MANDT
inner join DEP.dep.VBKD vbkd on vbkd.VBELN= vbak.VBELN and vbkd.MANDT=vbak.MANDT
inner join DEP.dep.VBRP vbrp on vbrp.VGBEL=lips.VBELN and vbrp.MANDT=lips.MANDT AND lips.POSNR = vbrp.VGPOS
inner join DEP.dep.VBRK vbrk on vbrk.VBELN=vbrp.VBELN and vbrp.MANDT=vbrk.MANDT
inner join SAP_FactTable_GM p on p.VBELN=vbrp.VGBEL
inner join Fact_BestPaymaster bp on p.CustomerId=bp.CustomerId
left join (select zs.VBELN as bill_no,ZZIDAT as submission_date,ZZP01 as pay_rule
from DEP.dep.ZSD_TAB_VBRK zs
where zs.MANDT='800') aa on aa.bill_no=vbrp.VBELN
CROSS APPLY (
SELECT DateDelta = CASE
WHEN vbrk.ZTERM ='Z003' THEN 1
when vbrk.ZTERM ='Z004' THEN 2
when vbrk.ZTERM ='Z005' THEN 3
when vbrk.ZTERM ='Z006' THEN 4
when vbrk.ZTERM ='Z007' THEN 5
when vbrk.ZTERM ='Z008' THEN 6
when vbrk.ZTERM ='Z009' THEN 7
when vbrk.ZTERM ='Z010' THEN 8
when vbrk.ZTERM ='Z011' THEN 9
when vbrk.ZTERM ='Z012' THEN 10
when vbrk.ZTERM ='Z013' THEN 12
when vbrk.ZTERM ='Z014' THEN 15
when vbrk.ZTERM ='Z015' THEN 20
when vbrk.ZTERM ='Z016' THEN 21
when vbrk.ZTERM ='Z017' THEN 24
when vbrk.ZTERM ='Z018' THEN 25
when vbrk.ZTERM ='Z019' THEN 30
when vbrk.ZTERM ='Z020' THEN 35
when vbrk.ZTERM ='Z021' THEN 40
when vbrk.ZTERM ='Z022' THEN 45
when vbrk.ZTERM ='Z023' THEN 60
when vbrk.ZTERM ='Z024' THEN 65
when vbrk.ZTERM ='Z025' THEN 70
when vbrk.ZTERM ='Z026' THEN 80
when vbrk.ZTERM ='Z027' THEN 90
when vbrk.ZTERM ='Z028' THEN 120
ELSE NULL END
) x
where likp.MANDT='800'
and PostingDate between @datefrom and @dateto
If I were you, I'd put all of the values in the CROSS APPLY into a table.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply