/* TC Bom ImPrecice: listet alle BOMLines - via - latest Revision */
SELECT
  i.puid         AS BOML_i_puid,
  i.pitem_id     AS BOML_pitem_id,
  ir.puid        AS BOML_ir_puid,
  ir.pitem_revision_id AS BOML_pitem_revision_id,
  bo.pseq_no     AS BOML_pseq_no,
  bo.puid        AS BOML_puid,
  bo.rnotes_refu AS BOML_OcN_ptt_puid,
  bvr.pstruct_last_mod_date AS BOMV_pstruct_last_mod_date
FROM
            infodba.PITEM i2
 INNER JOIN infodba.PITEMREVISION ir2 ON (i2.puid = ir2.ritems_tagu)
 INNER JOIN infodba.PSTRUCTURE_REVISIONS ps ON (ir2.puid = ps.puid)
 INNER JOIN infodba.PPSBOMVIEWREVISION bvr ON (ps.pvalu_0 = bvr.puid)
 INNER JOIN infodba.PPSOCCURRENCE bo ON (bvr.puid = bo.rparent_bvru)
 INNER JOIN infodba.PITEM i ON (bo.rchild_itemu = i.puid)
 INNER JOIN infodba.PITEMREVISION ir ON (i.puid = ir.ritems_tagu)

 LEFT JOIN infodba.PPSBOMVIEW bv on (bvr.rbom_viewu = bv.puid)
 LEFT JOIN infodba.PPSVIEWTYPE bvt on (bvt.puid = bv.rview_typeu)
WHERE
     upper(bvt.pname) = 'VIEW'
 AND ir2.pitem_revision_id = :para_ir_pitem_revision_id
 AND i2.pitem_id = :para_i_pitem_id
 AND ir.pitem_revision_id = 
 (SELECT max(ir3.pitem_revision_id) AS item_revision_id
  FROM infodba.PITEMREVISION ir3, infodba.PITEM i3
  WHERE i3.puid = i.puid AND ir3.ritems_tagu = i3.puid GROUP BY i3.puid)
;
  

