Re: Compare closed RMA's to other than closed RTV
I think this will do it:
select *
from SVC35000 r
inner join SVC05501 t
on r.RETTYPE = t.RETTYPE
inner join SVC35200 l
on r.RETDOCID = l.RETDOCID
and r.Return_Record_Type = l.Return_Record_Type
inner join SVC35210 p
on l.RETDOCID = p.RETDOCID
and l.Return_Record_Type = p.Return_Record_Type
and l.LNSEQNBR = p.LNSEQNBR
inner join
(
select RTV_Number, RTV_Type, RTV_Return_Status
from SVC05600
union all
select RTV_Number, RTV_Type, RTV_Return_Status
from SVC35600
) rtv
on p.SVC_Document_Number = rtv.RTV_Number
inner join SVC05003 rtvt
on rtv.RTV_Type = rtvt.RTV_Type
where r.RETSTAT = t.Close_Status
and rtv.RTV_Return_Status <> RTV_Closed_Status
and p.SVC_Process_Type = 2