/* Bom Tree Combo */
SELECT DISTINCT BOM_ID,
	   BOM_VERSION,
	   DECODE( BOM_ID,
	   		   :COMPARE_BOM_ID, 'selected',
			   NULL ) AS SELECTED
FROM
(
			   
SELECT bo.BOM_ID,
	   bo.BOM_VERSION ||'.'|| bo.BOM_LIFECYCLE AS BOM_VERSION,
	   DECODE( bo.BOM_ID,
	   		   :COMPARE_BOM_ID, 'selected',
			   NULL ) AS SELECTED

  FROM ( 
		SELECT bo.BOM_ID, bo.BOM_VERSION ||'.'|| bo.BOM_LIFECYCLE AS VERSION
		  FROM BOMS bo, BOM_STATE bs, PRODUCTION_BOM pm
		 WHERE bo.BRANCH_ID = :BRANCH_ID
		 AND bs.STATE_ID = pm.STATE_ID
		 AND bs.BOM_ID = bo.BOM_ID
	  ) qry,
	  BOMS bo
 WHERE qry.BOM_ID = bo.BOM_ID	 
)
ORDER BY BOM_VERSION desc
