DYNAMIC RESULT SETS 1
LANGUAGE SQL
ss: BEGIN
            
	            BEGIN
					    DECLARE crs CURSOR WITH RETURN FOR
					   SELECT DISTINCT
					            dde.Id,
					            ddv.ReferenceName,
					            ddv.ReferenceDdsTypeId,
					            ddv.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 dde
					          RIGHT OUTER JOIN DDCLValue ddv ON UPPER(dde.Name) = UPPER(ddv.ReferenceName)
					                                      AND dde.DdsTypeId = ddv.ReferenceDdsTypeId
					          INNER JOIN DDCLProperty ddp ON ddv.PropertyId = ddp.Id
					          INNER JOIN DDCLElement AS DDCLElementParent ON ddv.ElementId = DDCLElementParent.Id
					          LEFT OUTER JOIN DDCLSourceInfo AS ElementSourceInfo ON dde.SourceInfo = ElementSourceInfo.Id
					          LEFT OUTER JOIN Programs AS Programs_1 ON ElementSourceInfo.ProgramId = Programs_1.ProgramID
					          LEFT OUTER JOIN Occurrences AS Occurrences_1 ON Programs_1.OccurID = Occurrences_1.OccurID
					          LEFT OUTER JOIN Paths AS Paths_1 ON Occurrences_1.PathID = Paths_1.PathID
					          INNER JOIN DDCLSourceInfo AS CallSourceInfo ON ddv.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 ddv.ReferenceDdsTypeId = 4
					           AND  UPPER(ddp.Name) = 'CALL'
					           AND DDCLElementParent.DdsTypeId IN (27, 28)
					           AND DDCLElementParent.Id IN (SELECT * FROM SESSION.numeric_param_temp)
					     ORDER BY ddv.ReferenceName;

				       OPEN crs;
				
                END;
END ss	




