SELECT
  COALESCE(X.SalesBudget, 0) AS SalesBudget,
  COALESCE(X.CancelBudget, 0) AS CancelBudget,
  COALESCE(X.AutoBudget, 0) AS AutoBudget,
  COALESCE(X.ManualBudget, 0) AS ManualBudget,
  (COALESCE(X.SalesBudget, 0) + COALESCE(X.CancelBudget, 0) + COALESCE(X.AutoBudget, 0) + COALESCE(X.ManualBudget, 0)) AS TotalBudget
FROM (
  SELECT
    ( SELECT SUM(BU.Amount) FROM taBudget AS BU
      WHERE
        ((BU.Year * 100 + BU.Month) BETWEEN (YEAR(@aFromDate) * 100 + MONTH(@aFromDate)) AND (YEAR(@aToDate) * 100 + MONTH(@aToDate))) AND
        (BU.BudgetType = 'SalesRetainerGrowth')
        @pBranchID
        @pProductID
    ) AS SalesBudget,
    ( SELECT SUM(BU.Amount) FROM taBudget AS BU
      WHERE
        ((BU.Year * 100 + BU.Month) BETWEEN (YEAR(@aFromDate) * 100 + MONTH(@aFromDate)) AND (YEAR(@aToDate) * 100 + MONTH(@aToDate))) AND
        (BU.BudgetType = 'CancellationRetainerGrowth')
        @pBranchID
        @pProductID
    ) AS CancelBudget,
    ( SELECT SUM(BU.Amount) FROM taBudget AS BU
      WHERE
        ((BU.Year * 100 + BU.Month) BETWEEN (YEAR(@aFromDate) * 100 + MONTH(@aFromDate)) AND (YEAR(@aToDate) * 100 + MONTH(@aToDate))) AND
        (BU.BudgetType = 'AutoIncreaseRetainerGrowth')
        @pBranchID
        @pProductID
    ) AS AutoBudget,
    ( SELECT SUM(BU.Amount) FROM taBudget AS BU
      WHERE
        ((BU.Year * 100 + BU.Month) BETWEEN (YEAR(@aFromDate) * 100 + MONTH(@aFromDate)) AND (YEAR(@aToDate) * 100 + MONTH(@aToDate))) AND
        (BU.BudgetType = 'ManualRetainerGrowth')
        @pBranchID
        @pProductID
    ) AS ManualBudget
) AS X