SELECT a.TOU_TOOL as TOOLCODE,
a.TOU_ACT as ACTIVITYTRADE,
a.TOU_MRC as DEPARTMENT,
a.TOU_QTY as QUANTITY,
TOU_DATEUSED as DATEUSED,
a.TOU_HOURS as HOURSUSED,
a.TOU_SPLITUSAGE as SPLITUSAGE,
b.TOO_DESC as TOOLDESCRIPTION,
case e.evt_object when (select e1.evt_object from r5events e1 where e1.evt_code= <param.workordernum> and e1.evt_multiequip = '+' and e1.evt_code=e.evt_code) then <param.woheaderequipment> else e.evt_object end as EQUIPMENT,
e.evt_code as RELATEDWORKORDER
FROM R5TOOLUSAGE a ,R5TOOLS b ,r5events e
where a.TOU_TOOL = b.TOO_CODE and
(case when e.EVT_JOBTYPE='MEC'  then e.EVT_ROUTEPARENT else e.evt_code end) = <param.workordernum> and a.TOU_EVENT=e.evt_code order by a.TOU_DATEUSED
