/* TCE BomView ImPrecice
   listet alle BOMLines der höchsten Revision nach Buchstabe
   der 1. Ebene einer Baugruppe auf join umgestellt 10.08.2010 
   Example:  Tc DB tceng  
     :para_i_pitem_id = impraeziese1 
     :para_ir_pitem_revision_id = B
*/
SELECT
  i.pitem_id AS item,
  ir.pitem_revision_id AS rev,
  ir.puid AS ir_puid
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)
WHERE
  i2.pitem_id = :para_i_pitem_id
  AND ir2.pitem_revision_id = :para_ir_pitem_revision_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) 
