select cl.*,
ACK_FOLLOWUPEVENT || '-' || ACK_FOLLOWUPACT AS ACK_FOLLOWUPWOACT,
ack_frompoint + COALESCE(ob.obj_frompoint,0) frompoint,
ack_topoint + COALESCE(ob.obj_frompoint,0) topoint,
ack_reference,
ack_color,
CASE WHEN ack_requiredtoclose = 'REG' then '+' ELSE '-' END AS ack_regulated,
ob.obj_linearrefuom LINEARREFUOM,
ob.OBJ_DESC as equipmentdescription,
ob.OBJ_CLASS as classcode,
ob.OBJ_CLASS_ORG as classorg,
asp_desc                                     AS ack_aspect_desc     ,
poi_desc                                     AS ack_point_desc      ,
fnd_desc                                     AS ack_finding_desc    ,
case when
  (select count(*) count_1 from R5ADDETAILS  WHERE add_code=ack_taskchecklistcode AND add_rentity='TCLI' AND add_lang=<parameter.language> )> 0 then '+' else '-' end as ACK_COMMENTS
FROM R5actchecklists cl
LEFT OUTER JOIN
r5findings fin
ON
fnd_code= ack_finding
LEFT OUTER JOIN
r5aspects asp
ON
asp_code= ack_aspect
LEFT OUTER JOIN
r5points poi
ON
poi_point         = ack_point
AND poi_pointtype =ack_pointtype
AND poi_object    = ack_object
AND poi_object_org= ack_object_org
LEFT OUTER JOIN R5OBJECTS ob ON ACK_OBJECT = OBJ_CODE and ACK_OBJECT_ORG = obj_org
LEFT OUTER JOIN r5activities act ON ack_act = act_act AND ack_event = act_event
WHERE COALESCE(ACK_EVENT,ACK_ENTITYKEY) =<param.workordernum>
AND COALESCE(act.act_parent, act.act_act,1) = COALESCE(<param.activitytrade>,1)
AND (<param.jobseq> IS NULL OR <param.jobseq>  = 0 OR act.act_seq = <param.jobseq>)
ORDER BY ack_routesequence, ack_routeline, ack_object, ack_sequence, ack_occurrence

