Hi, I am trying to get this code working in another query and not having much luck. I tried to embed within existing query. I think I just need help with the structure.
select
so.ofrom,
o.sord_sordidx,
o.sord_num,
o.cust_code,
s.style_stylecode,
o.style_ref1_c as Brand,
o.style_ref2_c as Dept,
o.style_ref3_c as ProdGroup,
o.style_ref4_c as busgroup,
o.style_ref5_c as AccManag,
o.style_ref9_c as season,
o.style_ref10_c as yr,
st.cost as budgetcost,
st.estcost as budsell,
sp.price as rrp,
st.margin as fm,
o.sord_gendate,
o.sord_duef,
o.sord_cand,
a.log_date as changedate,
al.old_value as olddate,
al.new_value as newdate,
m.memfull as whochanged,
o.sozd_orig_1,
o.sozd_invq_1,
o.sozd_compl_qty_1,
s.sord_num,
s.sord_gldate,
s.sord_chad,
s.sord_despdate,
s.sozd_outst_qty_1,
s.sozd_fgross_1,
s.sozd_fnet_1,
s.sozd_fdisc_1,
s.sozd_tcost_1,
bs.code as bomcode,
si.code as supplier,
bom.fcost as unitforeign,
bom.cost as unitlocal
from (
select
so.ofrom,
o.sord_sordidx,
o.sord_num,
o.cust_code,
s.style_stylecode,
o.style_ref1_c as Brand,
o.style_ref2_c as Dept,
o.style_ref3_c as ProdGroup,
o.style_ref4_c as busgroup,
o.style_ref5_c as AccManag,
o.style_ref9_c as season,
o.style_ref10_c as yr,
st.cost as budgetcost,
st.estcost as budsell,
sp.price as rrp,
st.margin as fm,
o.sord_gendate,
o.sord_duef,
o.sord_cand,
a.log_date as changedate,
al.old_value as olddate,
al.new_value as newdate,
m.memfull as whochanged,
o.sozd_orig_1,
o.sozd_invq_1,
o.sozd_compl_qty_1,
s.sord_num,
s.sord_gldate,
s.sord_chad,
s.sord_despdate,
s.sozd_outst_qty_1,
s.sozd_fgross_1,
s.sozd_fnet_1,
s.sozd_fdisc_1,
s.sozd_tcost_1,
bs.code as bomcode,
si.code as supplier,
bom.fcost as unitforeign,
bom.cost as unitlocal,
rank() over (partition by o.sord_num order by al.aud_date desc) as rn
FROM
SA_DAVID_ORDERSCURRENT o,
SA_DAVID_SALESCURRENT s,
sord so,
styles st,
sprice_style sp,
bom_style bs,
supplier si,
bomtbl bom,
ap21log a,
ap21log_audit al,
member m ,
refcode r,
sord ord
WHERE
o.sord_sordidx (+)= so.ofrom
and so.sordidx = s.sord_sordidx
--and so.ofrom(+) = o.sord_sordidx(+)
and o.style_styleidx = st.styleidx (+)
and s.style_styleidx = st.styleidx
and o.style_styleidx = sp.styleidx (+)
and sp.rcidx(+) ='40857'
--and o.style_ref1_c = 'ACCESSORIES'
and so.active = 1
--and o.clr_clrcode = s.clr_clrcode
--and o.sord_num = 24680
and st.DEF_BSIDX = bs.bsidx
--and i.bscsidx = st.DEF_BSIDX
--and i.styleidx(+) = st.styleidx
--and id.icidx = i.icidx
and bom.suppidx= si.supidx
and bs.active = 1
and bom.styleidx = st.styleidx
and bom.bsidx = bs.bsidx
and bom.active = 1
and pbomidx = 0
and compcode = 'O/S SUPPLY'
and a.fromidx = ord.sordidx (+)
and o.sord_sordidx = ord.sordidx
and a.memidx = m.memidx
and a.typeidx = r.rcidx
and r.rcidx = 622
and a.logidx (+) = al.logidx
group by
so.ofrom,
o.sord_sordidx,
o.sord_num,
o.cust_code,
s.style_stylecode,
o.style_ref1_c ,
o.style_ref2_c ,
o.style_ref3_c ,
o.style_ref4_c ,
o.style_ref5_c ,
o.style_ref9_c ,
o.style_ref10_c,
st.cost,
st.estcost,
sp.price,
st.margin,
o.sord_gendate,
o.sord_duef,
o.sord_cand,
a.log_date,
al.old_value,
al.new_value,
m.memfull,
o.sozd_orig_1,
o.sozd_invq_1,
o.sozd_compl_qty_1,
s.sord_num,
s.sord_gldate,
s.sord_chad,
s.sord_despdate,
s.sozd_outst_qty_1,
s.sozd_fgross_1,
s.sozd_fnet_1,
s.sozd_fdisc_1,
s.sozd_tcost_1,
bs.code,
si.code,
bom.fcost
bom.cost
)
-- and al.old_value is not null
--and o.sord_num = '29895'
where rn = 1;