SELECT GLSummary.Company_Key
,GLSummary.GLAccount_Key
,SUM(GLSummary.Debit) AS Debit
,GLSummary.Project_Key
,SUM(GLSummary.Credit) AS Credit
,Max(FinancialPeriod.FinancialPeriod) AS FinancialPeriod
,Max(FinancialPeriod.FinancialPeriod_Key) AS FinancialPeriod_Key
FROM
FinancialPeriod
INNER JOIN GLSummary
ON FinancialPeriod.FinancialPeriod_Key = GLSummary.FinancialPeriod_Key
WHERE
(FinancialPeriod.FinancialPeriod)<='12/31/2011'
GROUP BY
GLSummary.Company_Key
,GLSummary.GLAccount_Key
,GLSummary.Project_Key
UNION
SELECT
GLSummary.Company_Key
,GLSummary.GLAccount_Key
,SUM(GLSummary.Debit) AS Debit
,GLSummary.Project_Key
,SUM(GLSummary.Credit) AS Credit
,(FinancialPeriod.FinancialPeriod) AS FinancialPeriod
,(FinancialPeriod.FinancialPeriod_Key) AS FinancialPeriod_Key
FROM
FinancialPeriod
INNER JOIN GLSummary
ON FinancialPeriod.FinancialPeriod_Key = GLSummary.FinancialPeriod_Key
WHERE
(FinancialPeriod.FinancialPeriod)>='1/1/2012'
GROUP BY
GLSummary.Company_Key
,GLSummary.GLAccount_Key
,GLSummary.Project_Key
,FinancialPeriod.FinancialPeriod
,FinancialPeriod.FinancialPeriod_Key