W
walemly
I have a trial balance master table (TB Master) with the following
fields:
Period (text, YYMM format)
CoNo
AcctNo
AcctName
Balance
This table contains trial balance records for multiple periods. As each
new period passes, I append that month's records to the master table.
I'm trying to create a query that will do the following:
1. Prompt the user (via a parameter) for the month to report on
2. Automatically calculate the previous calendar year end period using
the value provided in 1.
3. Match the records for the two different periods on CoNo and AcctNo
4. Display the balance for the prior year end, the period reported on,
and the difference between the two.
I've worked out the steps using the QBE to join TB Master to itself and
to calculate the prior year end period from the parameter period and
display and calculate the desired balances. My problem is that there
are some additional accounts during the prior year end that are no
longer present in the current period reported on in the parameter. I
know I have to use a full outer join in order to present all the sought
records but I've been unable to display anything other than the records
that are present in both periods in the full outer joins I've attempted
so far. I feel like what I want is doable, I just can't get the SQL
where I need it to be. Any help with tweaking my SQL code below or in
advising me how I need to tweak it will be greatly appreciated.
Alan
SELECT [TB Master].Period, [TB Master].CoNo, [TB Master].AcctNo, [TB
Master].AcctName, [TB Master_1]![Balance] AS PrevYEBal, [TB
Master]![Balance] AS CurMonBal, Nz([TB Master]![Balance])-Nz([TB
Master_1]![Balance]) AS BalDiff
FROM [TB Master] LEFT JOIN [TB Master] AS [TB Master_1] ON ([TB
Master].AcctNo = [TB Master_1].AcctNo) AND ([TB Master].CoNo = [TB
Master_1].CoNo)
WHERE (([TB Master].Period)=[Enter month to report (YYMM):]) AND (([TB
Master_1].Period)=Format(Val(Left([Enter month to report
(YYMM):],2))-1,"00") & "12"))
UNION SELECT [TB Master].Period, [TB Master_1].CoNo, [TB
Master_1].AcctNo, [TB Master_1].AcctName, [TB Master_1]![Balance] AS
PrevYEBal, [TB Master]![Balance] AS CurMonBal, Nz([TB
Master]![Balance])-Nz([TB Master_1]![Balance]) AS BalDiff
FROM [TB Master] RIGHT JOIN [TB Master] AS [TB Master_1] ON ([TB
Master].AcctNo = [TB Master_1].AcctNo) AND ([TB Master].CoNo = [TB
Master_1].CoNo)
WHERE (([TB Master].Period)=[Enter month to report (YYMM):]) AND (([TB
Master_1].Period)=Format(Val(Left([Enter month to report
(YYMM):],2))-1,"00") & "12"))
ORDER BY CoNo, AcctNo;
fields:
Period (text, YYMM format)
CoNo
AcctNo
AcctName
Balance
This table contains trial balance records for multiple periods. As each
new period passes, I append that month's records to the master table.
I'm trying to create a query that will do the following:
1. Prompt the user (via a parameter) for the month to report on
2. Automatically calculate the previous calendar year end period using
the value provided in 1.
3. Match the records for the two different periods on CoNo and AcctNo
4. Display the balance for the prior year end, the period reported on,
and the difference between the two.
I've worked out the steps using the QBE to join TB Master to itself and
to calculate the prior year end period from the parameter period and
display and calculate the desired balances. My problem is that there
are some additional accounts during the prior year end that are no
longer present in the current period reported on in the parameter. I
know I have to use a full outer join in order to present all the sought
records but I've been unable to display anything other than the records
that are present in both periods in the full outer joins I've attempted
so far. I feel like what I want is doable, I just can't get the SQL
where I need it to be. Any help with tweaking my SQL code below or in
advising me how I need to tweak it will be greatly appreciated.
Alan
SELECT [TB Master].Period, [TB Master].CoNo, [TB Master].AcctNo, [TB
Master].AcctName, [TB Master_1]![Balance] AS PrevYEBal, [TB
Master]![Balance] AS CurMonBal, Nz([TB Master]![Balance])-Nz([TB
Master_1]![Balance]) AS BalDiff
FROM [TB Master] LEFT JOIN [TB Master] AS [TB Master_1] ON ([TB
Master].AcctNo = [TB Master_1].AcctNo) AND ([TB Master].CoNo = [TB
Master_1].CoNo)
WHERE (([TB Master].Period)=[Enter month to report (YYMM):]) AND (([TB
Master_1].Period)=Format(Val(Left([Enter month to report
(YYMM):],2))-1,"00") & "12"))
UNION SELECT [TB Master].Period, [TB Master_1].CoNo, [TB
Master_1].AcctNo, [TB Master_1].AcctName, [TB Master_1]![Balance] AS
PrevYEBal, [TB Master]![Balance] AS CurMonBal, Nz([TB
Master]![Balance])-Nz([TB Master_1]![Balance]) AS BalDiff
FROM [TB Master] RIGHT JOIN [TB Master] AS [TB Master_1] ON ([TB
Master].AcctNo = [TB Master_1].AcctNo) AND ([TB Master].CoNo = [TB
Master_1].CoNo)
WHERE (([TB Master].Period)=[Enter month to report (YYMM):]) AND (([TB
Master_1].Period)=Format(Val(Left([Enter month to report
(YYMM):],2))-1,"00") & "12"))
ORDER BY CoNo, AcctNo;