AS SELECT 
   SCLSystemFiles.Name AS [File Name], 
   ProgramAliases.AliasName AS ProgramName, 
   Statements.Description AS [Statement type], 
   Count(Distinct OccurrencesStmt.OccurID) AS Expr1, '' 
    , (''+ProgramAliases.AliasName) 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 Programs ON OccurrencesStmt.ProgID = Programs.ProgramID
	  INNER JOIN ProgramAliases ON Programs.ProgramID = ProgramAliases.ProgramId and ProgramAliases.AliasType = 0
	  INNER JOIN Statements ON StatementReference.StatementType = Statements.StatementType 
WHERE 
(
   StatementReference.ResourceType=9
   AND SCLSystemFiles.Name is not null
   AND (Files.TypeCode <> 32 OR Files.TypeCode IS NULL)
   AND Programs.ProgramTypeID in (19) 
) 
GROUP BY SCLSystemFiles.Name, ProgramAliases.AliasName, Statements.Description 
ORDER BY SCLSystemFiles.Name, k, Statements.Description