AS SELECT DISTINCT 
	DDCLElement_SCREEN.Id, 
	DDCLElement_SCREEN.Name as Name, 
	DDCLElement_SCREEN.DdsTypeId, 
	DDCLElementParent.Id AS ParentId, 
	ElementSourceInfo.StartRow AS ElementStartRow, 
	ElementSourceInfo.EndRow AS ElementEndRow, 
	Paths_1.PathStr AS ElementPathStr, 
	CallSourceInfo.StartRow AS CallStartRow, 
	CallSourceInfo.EndRow AS CallEndRow, 
	Paths_2.PathStr AS CallPathStr 
FROM DDCLElement AS DDCLElement_SCREEN 
	INNER JOIN DDCLValue AS DDCLValue_1 ON DDCLElement_SCREEN.Id = DDCLValue_1.ElementId 
	INNER JOIN DDCLProperty AS DDCLProperty_1 ON DDCLValue_1.PropertyId=DDCLProperty_1.Id 
	INNER JOIN DDCLValue AS DDCLValue_2 ON DDCLValue_1.ReferenceName=DDCLValue_2.ReferenceName AND 
		DDCLValue_1.ReferenceDdsTypeId=DDCLValue_2.ReferenceDdsTypeId 
	INNER JOIN DDCLProperty AS DDCLProperty_2 ON DDCLValue_2.PropertyId=DDCLProperty_2.Id 
	INNER JOIN DDCLElement AS DDCLElementParent ON DDCLValue_2.ElementId=DDCLElementParent.Id 
	INNER JOIN DDCLSourceInfo AS ElementSourceInfo ON DDCLElement_SCREEN.SourceInfo=ElementSourceInfo.Id 
	INNER JOIN Programs AS Programs_1 ON ElementSourceInfo.ProgramId=Programs_1.ProgramID 
	INNER JOIN Occurrences AS Occurrences_1 ON Programs_1.OccurID=Occurrences_1.OccurID 
	INNER JOIN Paths AS Paths_1 ON Occurrences_1.PathID=Paths_1.PathID 
	INNER JOIN DDCLSourceInfo AS CallSourceInfo ON DDCLValue_1.SourceInfo=CallSourceInfo.Id 
	INNER JOIN Programs AS Programs_2 ON CallSourceInfo.ProgramId=Programs_2.ProgramID 
	INNER JOIN Occurrences AS Occurrences_2 ON Programs_2.OccurID=Occurrences_2.OccurID 
	INNER JOIN Paths AS Paths_2 ON Occurrences_2.PathID=Paths_2.PathID 
WHERE (DDCLElement_SCREEN.DdsTypeId=14) 
	AND (DDCLValue_1.ReferenceDdsTypeId=15) 
	AND (DDCLProperty_1.Name='DISPLAY-STRUCTURE') 
	AND (DDCLValue_2.ReferenceDdsTypeId=15) 
	AND (DDCLProperty_2.Name='DISPLAY-STRUCTURE') 
	AND (DDCLElementParent.DdsTypeId=11) 
	AND (DDCLElementParent.Id IN (SELECT * FROM #numeric_param_temp)) 
UNION
SELECT DISTINCT 
	DDCLElement_SCREEN.Id, 
	DDCLElement_SCREEN.Name as Name, 
	DDCLElement_SCREEN.DdsTypeId, 
	DDCLElementParent.Id AS ParentId, 
	ElementSourceInfo.StartRow AS ElementStartRow, 
	ElementSourceInfo.EndRow AS ElementEndRow, 
	Paths_1.PathStr AS ElementPathStr, 
	CallSourceInfo.StartRow AS CallStartRow, 
	CallSourceInfo.EndRow AS CallEndRow, 
	Paths_2.PathStr AS CallPathStr 
FROM DDCLElement AS DDCLElement_SCREEN 
	INNER JOIN DDCLValue AS DDCLValue_1 ON DDCLElement_SCREEN.Id = DDCLValue_1.ElementId 
	INNER JOIN DDCLProperty AS DDCLProperty_1 ON DDCLValue_1.PropertyId=DDCLProperty_1.Id 
	INNER JOIN DDCLValue AS DDCLValue_2 ON DDCLValue_1.ReferenceName=DDCLValue_2.ReferenceName AND 
		DDCLValue_1.ReferenceDdsTypeId=DDCLValue_2.ReferenceDdsTypeId 
	INNER JOIN DDCLProperty AS DDCLProperty_2 ON DDCLValue_2.PropertyId=DDCLProperty_2.Id 
	INNER JOIN DDCLElement AS DDCLElementParent ON DDCLValue_2.ElementId=DDCLElementParent.Id 
	INNER JOIN DDCLSourceInfo AS ElementSourceInfo ON DDCLElement_SCREEN.SourceInfo=ElementSourceInfo.Id 
	INNER JOIN Programs AS Programs_1 ON ElementSourceInfo.ProgramId=Programs_1.ProgramID 
	INNER JOIN Occurrences AS Occurrences_1 ON Programs_1.OccurID=Occurrences_1.OccurID 
	INNER JOIN Paths AS Paths_1 ON Occurrences_1.PathID=Paths_1.PathID 
	INNER JOIN DDCLSourceInfo AS CallSourceInfo ON DDCLValue_1.SourceInfo=CallSourceInfo.Id 
	INNER JOIN Programs AS Programs_2 ON CallSourceInfo.ProgramId=Programs_2.ProgramID 
	INNER JOIN Occurrences AS Occurrences_2 ON Programs_2.OccurID=Occurrences_2.OccurID 
	INNER JOIN Paths AS Paths_2 ON Occurrences_2.PathID=Paths_2.PathID 
WHERE (DDCLElement_SCREEN.DdsTypeId=14) 
	AND (DDCLValue_1.ReferenceDdsTypeId=15) 
	AND (DDCLProperty_1.Name='DISPLAY-STRUCTURE') 
	AND (DDCLValue_2.ReferenceDdsTypeId=15) 
	AND (DDCLProperty_2.Name='PRINT-FORM') 
	AND (DDCLElementParent.DdsTypeId=11) 
	AND (DDCLElementParent.Id IN (SELECT * FROM #numeric_param_temp)) 	
UNION
SELECT DISTINCT 
	DDCLElement.Id, 
	DDCLValue.ReferenceName as Name, 
	DDCLValue.ReferenceDdsTypeId, 
	DDCLValue.ElementId AS ParentId, 
	ElementSourceInfo.StartRow AS ElementStartRow, 
	ElementSourceInfo.EndRow AS ElementEndRow, 
	Paths_1.PathStr AS ElementPathStr, 
	CallSourceInfo.StartRow AS CallStartRow, 
	CallSourceInfo.EndRow AS CallEndRow, 
	Paths_2.PathStr AS CallPathStr 
FROM DDCLElement 
	RIGHT JOIN DDCLValue ON DDCLElement.Name=DDCLValue.ReferenceName AND DDCLElement.DdsTypeId=DDCLValue.ReferenceDdsTypeId 
	INNER JOIN DDCLProperty ON DDCLValue.PropertyId=DDCLProperty.Id 
	INNER JOIN DDCLElement AS DDCLElementParent ON DDCLValue.ElementId=DDCLElementParent.Id 
	LEFT JOIN DDCLSourceInfo AS ElementSourceInfo ON DDCLElement.SourceInfo=ElementSourceInfo.Id 
	LEFT JOIN Programs AS Programs_1 ON ElementSourceInfo.ProgramId=Programs_1.ProgramID 
	LEFT JOIN Occurrences AS Occurrences_1 ON Programs_1.OccurID=Occurrences_1.OccurID 
	LEFT JOIN Paths AS Paths_1 ON Occurrences_1.PathID=Paths_1.PathID 
	INNER JOIN DDCLSourceInfo AS CallSourceInfo ON DDCLValue.SourceInfo=CallSourceInfo.Id 
	INNER JOIN Programs AS Programs_2 ON CallSourceInfo.ProgramId=Programs_2.ProgramID 
	INNER JOIN Occurrences AS Occurrences_2 ON Programs_2.OccurID=Occurrences_2.OccurID 
	INNER JOIN Paths AS Paths_2 ON Occurrences_2.PathID=Paths_2.PathID 
WHERE (DDCLValue.ReferenceDdsTypeId=14) 
	AND (DDCLProperty.Name IN ('DISPLAY-STRUCTURE','PRINT-FORM')) 
	AND (DDCLElementParent.DdsTypeId=11) 
	AND (DDCLElementParent.Id IN (SELECT * FROM #numeric_param_temp)) 	
ORDER BY Name