AS SELECT pa.ProgramName, 
  SCLSystemFiles.Name AS [File Name], 
  Statements.Description AS [Statement type], 
  Count(Distinct OccurrencesStmt.OccurID) AS Expr1,
  '', (''+pa.ProgramName) as k  
FROM StatementReference INNER JOIN OccurrencesStmt ON StatementReference.OccurID = OccurrencesStmt.OccurID
     INNER JOIN Files ON StatementReference.ResourceID = Files.FileID
     INNER JOIN SCLSystemFiles on SCLSystemFiles.OccurId = Files.OccurID and SCLSystemFiles.fileId = Files.FileID
     INNER JOIN (SELECT Programs.ProgramTypeID, Programs.ProgramID, ProgramAliases.AliasName AS ProgramName FROM Programs 
				INNER JOIN ProgramAliases ON Programs.ProgramID = ProgramAliases.ProgramId and ProgramAliases.AliasType = 0)pa 
				ON OccurrencesStmt.ProgID = pa.ProgramID 
	 INNER JOIN Statements ON StatementReference.StatementType = Statements.StatementType 
WHERE (
   StatementReference.ResourceType=9
   AND (Files.TypeCode <> 32 OR Files.TypeCode IS NULL)
   AND pa.ProgramTypeid IN (19)
   AND SCLSystemFiles.Name is not null
 )
GROUP BY pa.ProgramName, SCLSystemFiles.Name, Statements.Description
ORDER BY k, SCLSystemFiles.Name