AS set NOCOUNT ON;
IF OBJECT_ID('tempdb..#programWithAncestor') IS NOT NULL DROP TABLE #programWithAncestor
			 SELECT * INTO #programWithAncestor 
			 FROM   fGetProgram_Ancestor_Aliases (NULL)

SELECT p.ProgramName AS ProgramName, 
	COUNT(DISTINCT OccurrencesStmt.OccurID) AS AssemblerBFP, p.AncestorName, p.AncestorID
  FROM  OccurrencesStmt INNER JOIN #programWithAncestor p ON OccurrencesStmt.ProgID=p.ProgramID
 WHERE (((p.OccurID)<>0) And p.programtypeid in (8, 15, 16))
 AND (p.ProgramID in (Select * from #numeric_param_temp))
 group BY p.AncestorName, p.ProgramName, p.AncestorID
 order by p.AncestorName, p.ProgramName, p.AncestorID