I have the following code which is used to run several reports. This code is one part of a larger subset of queries.
This query simply queries for the daily balance stored in a table (for reasons not discussed here). I'd like to use this query for one final report for the current day's balance. The problem is, the daily balance for the current day is not calculated until the after this query has been run. So, when using this query for the current day, the results of the query are blank. In order to use this for the current day (and calculate the current balance), I need the Balance to return 0, or something other than blank. I have tried using NZ for both the Balance and RunBalance with no resolve. I know I can formulate separate queries for this, but I'm trying to re-purpose what I can.
qFUEL_RUNBAL
Or, perhaps the problem could be corrected in the main query somehow if RunBal is null:
qFUEL_REPORTTOTALS
This query simply queries for the daily balance stored in a table (for reasons not discussed here). I'd like to use this query for one final report for the current day's balance. The problem is, the daily balance for the current day is not calculated until the after this query has been run. So, when using this query for the current day, the results of the query are blank. In order to use this for the current day (and calculate the current balance), I need the Balance to return 0, or something other than blank. I have tried using NZ for both the Balance and RunBalance with no resolve. I know I can formulate separate queries for this, but I'm trying to re-purpose what I can.
qFUEL_RUNBAL
SQL:
PARAMETERS [TempVars]![tmpEndDate] DateTime, [TempVars]![tmpAirline] Short;
SELECT tblBalance.TransactionDate, tblBalance.AirlineCompanyLookup, tblBalance.Balance AS Balance, (Select Sum(a.Balance)
From tblBalance as a
Where a.TransactionDate = [TempVars]![tmpEndDate]) AS RunBalance
FROM tblBalance INNER JOIN tblAirlines ON tblBalance.AirlineCompanyLookup = tblAirlines.AirlineID
WHERE (((tblBalance.TransactionDate)=[TempVars]![tmpStartDate] Or (tblBalance.TransactionDate) Is Null));
Or, perhaps the problem could be corrected in the main query somehow if RunBal is null:
qFUEL_REPORTTOTALS
SQL:
SELECT qFUEL_TRANSACTIONSNEW.AirlineCompany,
qFUEL_TRANSACTIONSNEW.AirlineCompanyLookup,
qFUEL_RUNPRVBAL.PrvBalance, qFUEL_TRANSACTIONSNEW.SumReceived,
[PrvBalance]+[SumReceived] AS Subtotal,
qFUEL_TRANSACTIONSNEW.SumIssued,
[PrvBalance]+[SumReceived]-[SumIssued] AS BookBalance,
qFUEL_TRANSACTIONSNEW.TotalReceived,
qFUEL_TRANSACTIONSNEW.TotalIssued,
[RunPrvBalance]+[TotalReceived] AS TotalSubtotal,
[TotalSubtotal]-[TotalIssued] AS TotalBookBalance,
Last(qFUEL_TANKVOLSUM.RunTankVol) AS LastOfRunTankVol,
Last(qFUEL_TRUCKVOLSUM.RunTruckVol) AS LastOfRunTruckVol,
[LastOfRunTankVol]+[LastOfRunTruckVol] AS TotalActualBalance,
[TotalActualBalance]-[TotalBookBalance] AS TotalGainLoss,
Round((([SumIssued]/[RunIssued])*[TotalGainLoss]),0) AS GainLoss,
(Select Sum(a.SumIssued)
From qFUEL_TRANSACTIONSNEW as a
Where a.AirlineCompanyLookup = AirlineCompanyLookup) AS RunIssued,
qFUEL_RUNPRVBAL.RunPrvBalance, Last(qFUEL_RUNBAL.RunBalance) AS LastOfRunBalance,
FormatPercent((([SumIssued])/([RunIssued]))) AS PctAirline,
[TotalActualBalance]-[LastOfRunBalance] AS InventoryDiff,
[TotalGainLoss]-[InventoryDiff] AS GainLossDiff,
[TotalGainLoss]/[RunIssued] AS PctGainLoss,
[SumIssued]/[RunIssued] AS UsedNumeric,
qFUEL_TRANSACTIONSNEW.MonthGainLoss0 AS MonthGainLoss,
[LastOfRunTankVol]+[LastOfRunTruckVol] AS TotalPhysInven,
[PrvBalance]+[SumReceived]-[SumIssued]+[MonthGainLoss] AS Balance
FROM qFUEL_TANKVOLSUM, qFUEL_TRUCKVOLSUM,
qFUEL_RUNBAL
INNER JOIN (qFUEL_TRANSACTIONSNEW
INNER JOIN qFUEL_RUNPRVBAL ON qFUEL_TRANSACTIONSNEW.AirlineCompanyLookup = qFUEL_RUNPRVBAL.AirlineCompanyLookup) ON qFUEL_RUNBAL.AirlineCompanyLookup = qFUEL_TRANSACTIONSNEW.AirlineCompanyLookup
GROUP BY qFUEL_TRANSACTIONSNEW.AirlineCompany, qFUEL_TRANSACTIONSNEW.AirlineCompanyLookup, qFUEL_RUNPRVBAL.PrvBalance, qFUEL_TRANSACTIONSNEW.SumReceived, qFUEL_TRANSACTIONSNEW.SumIssued, qFUEL_TRANSACTIONSNEW.TotalReceived, qFUEL_TRANSACTIONSNEW.TotalIssued, qFUEL_RUNPRVBAL.RunPrvBalance, qFUEL_TRANSACTIONSNEW.MonthGainLoss0;
Last edited: