select
a.*, ack.ack_frompoint + CAST( COALESCE( o.obj_frompoint, 0 ) AS NUMERIC( 24, 6 ) ) ack_frompoint,ack.ack_topoint  + CAST( COALESCE( o.obj_frompoint, 0 ) AS NUMERIC( 24, 6 ) ) ack_topoint
FROM r5actchecklists a, r5objects o,
(SELECT ack_code, ack_frompoint, ack_topoint
FROM   r5actchecklists
WHERE  ack_object = <param.object>
AND    ack_object_org =  <param.objorganization>
AND    ack_frompoint IS NOT NULL
AND    ack_topoint IS NOT NULL
AND    ack_loto IS NULL
AND    strftime('%Y-%m-%d', ack_updated) <= strftime('%Y-%m-%d', <param.effectivedate>)
UNION ALL
SELECT ack_code, lrf_frompoint, lrf_topoint
FROM   r5actchecklists a1, r5objlinearref
WHERE  <param.includerelatedequip> = '+'
AND    lrf_objcode = <param.object>
AND    lrf_objorg = <param.objorganization>
AND    lrf_displayonoverview = '+'
AND    ack_object = lrf_re_objcode
AND    ack_object_org = lrf_re_objorg
AND    ack_loto IS NULL
AND    strftime('%Y-%m-%d', ack_updated) <= strftime('%Y-%m-%d', <param.effectivedate>)
AND NOT EXISTS( SELECT 'x'
FROM   r5actchecklists a2
WHERE  ack_object = <param.object>
AND    ack_object_org = <param.objorganization>
AND    ack_frompoint IS NOT NULL
AND    ack_topoint IS NOT NULL
AND    ack_loto IS NULL
AND    strftime('%Y-%m-%d', ack_updated) <= strftime('%Y-%m-%d', <param.effectivedate>)
AND     a2.ack_code = a1.ack_code ) ) ack
where a.ack_code = ack.ack_code
AND o.obj_code = ack_object
AND o.obj_org = ack_object_org
