/* Data Tables */
SELECT dt.DT_ID,
	   dt.TABLE_NAME,
	   dt.REF_COLUMN_NAME,
	   dt.DISPLAY_COLUMN_NAME,
	   DECODE ( filter_setting.FILTER_COUNT,
	   		  	NULL, 'LIMG_DATA_TABLE_OFF',
				'LIMG_DATA_TABLE' ) AS FILTER_SETTINGS
	   
  FROM DATA_TABLES dt,
  	   (
	   
	    /* Get filter setting for this control */	   			   
		SELECT dt.DT_ID,
			   Count(*) AS FILTER_COUNT
		  FROM DATA_TABLES dt,
		  	   DATA_PERMISSIONS dp
		 WHERE dp.DT_ID = dt.DT_ID
		   AND dt.OBJ_ID = :OBJ_ID
		   AND dp.ROLE_ID = :ROLE_ID
		   AND dp.REF_COLUMN_VAL != 0
		 GROUP BY dt.DT_ID
		
		
		) filter_setting
  	   
 WHERE dt.OBJ_ID = :OBJ_ID
   AND filter_setting.DT_ID (+) = dt.DT_ID  
ORDER BY UPPER(dt.TABLE_NAME) 
