How should we Modify the Code ?
Proc sql;
create table SROin_2 as
select
/* Before = Faults */
before.urn,
before.Close_Date,
before.Close_Date as dayt,
before.dayt as fault_checked_date, /** 07/12/2010 - JW - Added this date in to statement **/
before.TECH_no1,
before.WORKORDER,
before.finding_desc,
before.solution_desc,
before.source_system_code,
before.franchise_Code,
before.account_no,
before.trucked_fault,
/* After = SROs */
/* PR-added COMPLETIONDATE (P0002373164)*/
after.ENTRYDATE,
after.ENTRYDATE as dayt,
after.COMPLETIONDATE,
after.workorder as SRO_WO,
after.SERVICE_CODE,
after.TECH_NO1 as A_Tech_No1
from Closed_Faults as before left join
SROs as after
on before.urn = after.urn
and before.dayt le after.dayt
and after.dayt lt (before.dayt + 1 + 1)
and after.urn ne ""
order by before.dayt, urn;
quit;
Modified Code
Proc SQL;
Create table SROin_2 as
Select
/* Before = Faults */
Coalesce(before.closeddate,open.schedule_date) as faultdate,
before.urn,
before.Close_Date,
before.Close_Date as dayt,
before.dayt as fault_checked_date, /** 07/12/2010 - JW - Added this date in to statement **/
before.TECH_no1,
before.WORKORDER,
before.finding_desc,
before.solution_desc,
before.source_system_code,
before.franchise_Code,
before.account_no,
before.trucked_fault,
/* After = SROs */
/* PR-added COMPLETIONDATE (P0002373164)*/
after.ENTRYDATE,
after.ENTRYDATE as dayt,
after.COMPLETIONDATE,
after.workorder as SRO_WO,
after.SERVICE_CODE,
after.TECH_NO1 as A_Tech_No1
from SROs as SRO
left join
Closed_Faults as before on sro.urn=before.urn
and SRO.Opendate lt (before.dayt+1)
left join
Open as Open ON SRO.URN = OPEN.URN
and SRO.Opendate lt (OPEN.SCHEDULE_DATE+1)
where Before.URN IS NOT NULL OR OPEN.URN IS NOT NULL
order by before.dayt,urn;
QUIT;