AS SELECT DISTINCT DDCLElement.Name
FROM DDCLElement 
WHERE 
 DDCLElement.DdsTypeId=28
 AND (DDCLElement.Id IN (SELECT * FROM #numeric_param_temp)) 
 and DDCLElement.Id not in (select id from 
	    (select DDCLElement.Id as id, DDCLValue.Value as name from DDCLElement
			    inner join	DDCLValue on DDCLElement.Id = DDCLValue.ElementId
			    inner join DDCLProperty on DDCLProperty.Id = DDCLValue.PropertyId and DDCLProperty.Name = 'PROGRAM-ID'
			where DDCLElement.DdsTypeId = 28    
		union
			select DDCLElement.Id as id, DDCLElement.Name as name from DDCLElement
			    left outer join DDCLProperty on DDCLProperty.ElementId = DDCLElement.Id and DDCLProperty.Name = 'PROGRAM-ID'
			where DDCLElement.DdsTypeId = 28 and DDCLProperty.Id is null  
		) as t   
							
		WHERE 
		 t.name in (Select  Programs_1.ProgramName FROM Programs INNER JOIN OccurrencesStmt ON Programs.ProgramID = OccurrencesStmt.ProgID 
					INNER JOIN StatementReference ON OccurrencesStmt.OccurID = StatementReference.OccurID 
					INNER JOIN Occurrences on Occurrences.OccurID=Programs.OccurID INNER JOIN Paths on Occurrences.PathID=Paths.PathID 
					INNER JOIN Programs AS Programs_1 ON StatementReference.ResourceID = Programs_1.ProgramID 
					WHERE (StatementReference.ResourceType = 5) AND Programs.OccurID <> 0))
ORDER BY DDCLElement.Name 