AS SELECT 
    pa.ProgramName, Paragraphs.ParaName AS [Procedure Name], 
    Paths.PathStr AS [Source File Name], 
    Resources.Name AS [Include Name], 
    Occurrences.StartRow AS Line,
    Paragraphs.NumOfStatements AS NumOfStmts,
    pa.ProgramID
FROM (Occurrences AS Occurrences_1 
    INNER JOIN (((Paragraphs INNER JOIN 
				(SELECT Programs.ProgramID, Programs.ProgramTypeID, ProgramAliases.AliasName AS ProgramName  FROM dbo.Programs 
					INNER JOIN ProgramAliases ON ProgramAliases.ProgramId = Programs.ProgramID and ProgramAliases.AliasType = 0) pa 
                ON Paragraphs.ProgramID = pa.ProgramID) 
        INNER JOIN Occurrences ON Paragraphs.OccurID = Occurrences.OccurID) 
        INNER JOIN Paths ON Occurrences.PathID = Paths.PathID) 
    ON Occurrences_1.PathID = Occurrences.PathID) 
    LEFT JOIN Resources ON Occurrences_1.OccurID = Resources.OccurID 
WHERE (((Paragraphs.OrdinalNum)<>1) 
    AND (pa.ProgramID in (Select * from #numeric_param_temp))
    AND (Paragraphs.IsExitPara=0)
    AND 
    ((Paragraphs.ParaID) Not In 
        (SELECT DISTINCT TOP 100 PERCENT Paragraphs.ParaID  
            FROM  Paragraphs INNER JOIN  StatementReference ON Paragraphs.ParaID = StatementReference.ResourceID 
            WHERE (StatementReference.ResourceType = 2))) 
            AND ((Occurrences_1.ResourceType)=5 
                Or (Occurrences_1.ResourceType)=13
                Or (Occurrences_1.ResourceType)=60 
                Or (Occurrences_1.ResourceType)=67)) 
            AND (pa.ProgramTypeID <> 1)
ORDER BY pa.ProgramName, pa.ProgramID, Resources.Name, Paragraphs.ParaName