select
m.mis_code as ADCCODE, 
m.mis_act as ACTIVITYTRADE,
cast(m.mis_act as nvarchar) as ACTIVITYTRADE_DISPLAY,
m.mis_date as ADDITIONALCOSTSDATE,
m.mis_price as COST,
m.mis_desc as COSTDESCRIPTION,
(SELECT uco_desc from r5ucodes where uco_rentity='WOCS'
and uco_code=m.mis_rtype) as COSTTYPE_DISPLAY,
m.mis_rtype AS COSTTYPE,
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,
m.mis_qty as QUANTITY,
e.evt_code as RELATEDWO
from r5misccosts m, r5events e, r5activities a where 
(case when e.EVT_JOBTYPE='MEC'  then e.EVT_ROUTEPARENT else e.evt_code end) = <param.workordernum> and m.mis_event=e.evt_code
and a.act_event=<param.workordernum> and e.evt_org =<param.organization> and m.mis_act = a.act_act and m.mis_qty<>0  ORDER BY m.mis_act 