CREATE VIEW [M_APBAL] AS SELECT LEDGER, NOMINAL, ACCOUNT, YEARCODE, PERIOD, SUM(VALUE) AS Balance, COUNT(*) AS DetCount, SUM(ACCCURRENCY) AS AccCurrency, SUM(USERVALUE) AS UserValue, COMPANYCODE FROM dbo.D_DETAILS GROUP BY LEDGER, NOMINAL, ACCOUNT, YEARCODE, PERIOD, COMPANYCODE HAVING (LEDGER IS NOT NULL) AND (ACCOUNT IS NOT NULL)