--[mssql:Native]
IF OBJECT_ID ('dbo.ReleasedTranGroups','V') IS NOT NULL DROP VIEW dbo.ReleasedTranGroups
GO 
CREATE VIEW dbo.ReleasedTranGroups
AS
SELECT 
    ROW_NUMBER() OVER (
        ORDER BY 
            p.CompanyID, 
            p.ProjectID, 
            p.AccountGroupID
    ) AS RowKey,
    p.CompanyID, 
    p.ProjectID, 
    p.AccountGroupID, 
    COUNT(*) AS ResultsSummed,
    SUM(p.Amount) AS [Amount], 
    SUM(p.TranCuryAmount) AS [TranCuryAmount], 
    SUM(p.ProjectCuryAmount) AS [ProjectCuryAmount], 
    SUM(p.ProjectCuryInvoicedAmount) AS [ProjectCuryInvoicedAmount],
    SUM(p.InvoicedAmount) AS [InvoicedAmount]
FROM PMTran p 
WHERE p.Released = 1
GROUP BY 
    p.CompanyID, 
    p.ProjectID, 
    p.AccountGroupID