AS SELECT DDCLElement.Name
FROM DDCLElement 
WHERE 
 DDCLElement.DdsTypeId=26
 AND (DDCLElement.Id IN (SELECT * FROM #numeric_param_temp)) 
 AND DDCLElement.id not in (
	select distinct DDCLElement.id
	from DDCLElement
	join DDCLValue on DDCLValue.ElementId=DDCLElement.Id 
	join DDCLProperty on DDCLElement.id = DDCLProperty.elementid
	where DDCLElement.DdsTypeId=26
	and DDCLElement.islocal='false'
	and DDCLValue.ValueTypeId in (2,4)
	and DDCLValue.ReferenceDdsTypeId=26 
	AND DDCLProperty.name = 'DIALOGUES'
 )
 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 
		AND DDCLValue.ReferenceDdsTypeId=DDCLElementChild.DdsTypeId 
	WHERE DDCLElement.DdsTypeId=25 
	AND DDCLValue.ReferenceDdsTypeId=26
	AND DDCLElementChild.Id IN (SELECT * FROM #numeric_param_temp) 
	AND DDCLValue.ValueTypeId in (2,4) 
	AND DDCLElement.islocal='false'
	AND DDCLProperty.Name='DIALOGUES' 	
 )
 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 
		AND DDCLValue.ReferenceDdsTypeId=DDCLElementChild.DdsTypeId 
	WHERE DDCLElement.DdsTypeId=26 
	AND DDCLValue.ReferenceDdsTypeId=26
	AND DDCLElementChild.Id IN (SELECT * FROM #numeric_param_temp) 
	AND DDCLProperty.Name='PROCESSING-STRUCTURE' 	
 )	
 AND DDCLElement.id not in (select DDCLElement.Id
	from DDCLElement inner join DDCLValue on DDCLElement.Id = DDCLValue.ElementId
	inner join DDCLProperty on DDCLProperty.Id = DDCLValue.PropertyId
	WHERE DDCLProperty.Name = 'TASK' AND DdsTypeId = 26   
	and DDCLValue.ReferenceName 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 