AS SELECT DISTINCT DDCLElement.Name
FROM DDCLElement 
WHERE 
 DDCLElement.DdsTypeId=10
 AND (DDCLElement.Id IN (SELECT * FROM #numeric_param_temp)) 
 AND DDCLElement.id not in (
	SELECT DISTINCT DDCLElementChild.Id 
	FROM DDCLElement 
		INNER JOIN DDCLValue ON DDCLElement.Id=DDCLValue.ElementId 
		INNER JOIN DDCLProperty ON DDCLValue.PropertyId=DDCLProperty.Id 
		INNER JOIN DDCLElement AS DDCLElementChild ON DDCLValue.ReferenceName=DDCLElementChild.Name 
	WHERE
		(DDCLElementChild.Id IN (SELECT * FROM #numeric_param_temp)) 
		AND (DDCLValue.ReferenceDdsTypeId=10) 
		AND DDCLValue.ValueTypeId in (2,4)
		AND (
			(DDCLElement.DdsTypeId=11 AND DDCLProperty.Name IN ('CHANGES','OUTPUT','PARAMETERS','PROCESSING-STRUCTURE','SELECTION','SINGULAR-VIEW','VARIABLES') )
			OR
			(DDCLElement.DdsTypeId=16 AND DDCLProperty.Name IN ('CHANGES','PROCESSING-STRUCTURE','SELECTION','SINGULAR-VIEW','VARIABLES') )
			OR
			(DDCLElement.DdsTypeId IN (27,28) AND DDCLProperty.Name IN ('PARAMETERS','PROCESSING-STRUCTURE','SELECTION','VIEW','VARIABLES') ) 
		) 
 	)
   AND DDCLElement.id not in (
  	select DISTINCT DDCLElement.id from 
  			DDCLElement inner join IdmsSubschemaSets on DDCLElement.name = IdmsSubschemaSets.SetName and DDCLElement.ddstypeid = 10
  				INNER JOIN StatementReference ON IdmsSubschemaSets.ID = StatementReference.ResourceID and StatementReference.ResourceType = 78
  				INNER JOIN OccurrencesStmt ON OccurrencesStmt.OccurID = StatementReference.OccurID
  				INNER JOIN Programs ON Programs.ProgramID = OccurrencesStmt.ProgID 
  )
ORDER BY DDCLElement.Name 
