drop table jde_rk.dbo.temp_123
select sdan8 Soldto,
DATEADD(dy, cast(SDTRDJ as varchar(10)) % 1000, DATEADD(yy, cast(SDTRDJ as varchar(10)) / 1000,-1)) OrdDate,
sddcto OrdTy,sddoco O#, sdglc GL,sdshan Shipto,rtrim(wwgnnm) +' '+wwsrnm "Owner Name",sdlitm I#,sddsc1 Dsc,sum(sdsoqs)Qty
,avg(cost02)Cost02,avg(cost21) Cost21,avg(cost25)Cost25,sum(cost02*sdsoqs) COGS,sum(cost21*sdsoqs) Sales,sum(cost25*sdsoqs)RBT,
(sum(cost21*sdsoqs)-sum(cost25*sdsoqs)) NetSale ,
Comm =case
when sdglc='PRCO' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.20
when sdglc='PRQU' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.20
when sdglc='PSFO' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.20
when sdglc='DDPR' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.25
when sdglc='LLEB' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.25
when sdglc='BBC4' then (sum(cost21*sdsoqs)-sum(cost25*sdsoqs))*.25
else 0 end,
sdmcu,abalph shiptoname,' ' hubname,
dc1.edan82 dc1Add,avg(isnull(dc1.eduncs,0)/10000) DC1per,dc1.edalph dc1alph,
dc2.edan82 dc2Add,avg(isnull(dc2.eduncs,0)/10000) DC2per,dc2.edalph dc2alph,
dc3.edan82 dc3Add,avg(isnull(dc3.eduncs,0)/10000) DC3per,dc3.edalph dc3alph,
dc4.edan82 dc4Add,avg(isnull(dc4.eduncs,0)/10000) DC4per,dc4.edalph dc4alph,
dcvp.edan82 dcvpAdd,avg(isnull(dcvp.eduncs,0)/10000) DCvpper,dcvp.edalph dcvpalph,
dcnc.edan82 dcncAdd,avg(isnull(dcnc.eduncs,0)/10000) DCncper,dcnc.edalph dcncalph,
avg(isnull(dc1.eduncs,0)+isnull(dc2.eduncs,0)+isnull(dc3.eduncs,0)+isnull(dc4.eduncs,0)+isnull(dcvp.eduncs,0)+isnull(dcnc.eduncs,0))/10000 "OR Total"
into jde_rk.dbo.temp_123 from proddta.f4211
left outer join proddta.f0101 on sdshan=aban8
left outer join proddta.f0111 on sdshan=wwan8
left outer join proddta.F5542845 dc1 on dc1.edglc=sdglc and sdan8=dc1.edan81 and sdtrdj>=dc1.edeftb and sdtrdj<=dc1.edefte and rtrim(dc1.edast)='DC1' and sddcto=dc1.eddcto
left outer join proddta.F5542845 dc2 on dc2.edglc=sdglc and sdan8=dc2.edan81 and sdtrdj>=dc2.edeftb and sdtrdj<=dc2.edefte and rtrim(dc2.edast)='DC2' and sddcto=dc2.eddcto
left outer join proddta.F5542845 dc3 on dc3.edglc=sdglc and sdan8=dc3.edan81 and sdtrdj>=dc3.edeftb and sdtrdj<=dc3.edefte and rtrim(dc3.edast)='DC3' and sddcto=dc3.eddcto
left outer join proddta.F5542845 dc4 on dc4.edglc=sdglc and sdan8=dc4.edan81 and sdtrdj>=dc4.edeftb and sdtrdj<=dc4.edefte and rtrim(dc4.edast)='DC4' and sddcto=dc4.eddcto
left outer join proddta.F5542845 dcvp on dcvp.edglc=sdglc and sdan8=dcvp.edan81 and sdtrdj>=dcvp.edeftb and sdtrdj<=dcvp.edefte and rtrim(dcvp.edast)='DCVP' and sddcto=dcvp.eddcto
left outer join proddta.F5542845 dcnc on dcnc.edglc=sdglc and sdan8=dcnc.edan81 and sdtrdj>=dcnc.edeftb and sdtrdj<=dcnc.edefte and rtrim(dcnc.edast)='DCNC' and sddcto=dcnc.eddcto
left outer join vAllcostinRow on sdlitm=colitm and sdmcu=comcu
--left outer join zdev.dbo.hubmgr on sdshan=hubno
where sdkcoo=600 and sdnxtr=999 and sdlttr<>980 and sdlnty='S' and SDTRDJ>=110032 and SDTRDJ<=110059
group by sdtrdj,sddcto,sdglc,abac11,sdshan,abalph,sdlitm,sddsc1,wwgnnm,wwsrnm,sdmcu,sdan8--,hubname
,dc1.edan82,dc1.edalph,dc2.edan82,dc2.edalph,dc3.edan82,dc3.edalph,dc4.edan82,dc4.edalph,dcvp.edan82,
dcvp.edalph,dcnc.edan82,dcnc.edalph,sddoco
update jde_rk.dbo.temp_123 set hubname =isnull(b.hubname,'')
from jde_rk.dbo.temp_123
left outer join vHubmgr b on hubno=Soldto
select * from jde_rk.dbo.temp_123
No comments:
Post a Comment