DYNAMIC RESULT SETS 1
LANGUAGE SQL
ss: BEGIN


	            BEGIN
              
					    DECLARE crs CURSOR WITH RETURN FOR	 
							SELECT DISTINCT
									prgAlsxyz.ProgramID,
					            	prgAlsxyz.AliasName AS ProgramName,
						            pth.PathStr,
						            occ.StartRow,
						            0 AS Expr1
						     FROM Programs prg
						          INNER JOIN Occurrences occ ON prg.OccurID = occ.OccurID
						          INNER JOIN Paths pth ON occ.PathID = pth.PathID
				                                                AND NOT(
				                                                        --UPPER(pth.PathStr) LIKE '%' || UPPER(prg.ProgramName) 
																		(
																		  LOCATE_IN_STRING(UPPER(pth.PathStr), UPPER(prg.ProgramName), -1) > 0  -- check existence
																		  AND 
																		  LOCATE_IN_STRING(UPPER(pth.PathStr), UPPER(prg.ProgramName), -1) = LENGTH(pth.PathStr) + 1 - LENGTH(prg.ProgramName) -- last position in string
																		)
																	     OR 
																	     --UPPER(pth.PathStr) LIKE '%' || UPPER(prg.ProgramName) || '.' || '%'
																	      LOCATE_IN_STRING(UPPER(pth.PathStr), UPPER(prg.ProgramName) || '.', 1) > 0  -- check existence 
				                                                       )
								  INNER JOIN ProgramAliases prgAlsxyz ON prg.ProgramId = prgAlsxyz.ProgramID
									AND prgAlsxyz.AliasType = 0
							 WHERE    prg.ProgramTypeID = 1
						              AND prg.ProgramID IN (SELECT * FROM SESSION.numeric_param_temp) 
						     ORDER BY prgAlsxyz.AliasName,
						              pth.PathStr,
						              occ.StartRow;

                        OPEN crs;
                        
                  END;       
 END ss	






