Jill said:
Thank you so much for your help.
Option 1: This is the SQL from the combined table
SELECT [Qry:_jbh_InvoiceTotal

ayCurrentYear].DayofMonthCurrent,
[Qry:_jbh_InvoiceTotal

ayPriorYear].DayofMonthPrior,
[Qry:_jbh_InvoiceTotal

ayCurrentYear].CurrentYrInvoiceAmount,
[Qry:_jbh_InvoiceTotal

ayPriorYear].PriorYrInvAmount,
IIf(IsNull([CurrentYrInvoiceAmount]),0,[CurrentYrInvoiceAmount])-IIf(IsNull([PriorYrInvAmount]),0,[PriorYrInvAmount])
AS Comparison
FROM (dbo_Clients LEFT JOIN [Qry:_jbh_InvoiceTotal

ayCurrentYear] ON
dbo_Clients.ID = [Qry:_jbh_InvoiceTotal

ayCurrentYear].ID) LEFT JOIN
[Qry:_jbh_InvoiceTotal

ayPriorYear] ON dbo_Clients.ID =
[Qry:_jbh_InvoiceTotal

ayPriorYear].ID
WHERE ((([Qry:_jbh_InvoiceTotal

ayCurrentYear].CurrentYrInvoiceAmount) Is
Not Null)) OR ((([Qry:_jbh_InvoiceTotal

ayPriorYear].PriorYrInvAmount) Is
Not Null))
ORDER BY [Qry:_jbh_InvoiceTotal

ayPriorYear].DayofMonthPrior;
Option 2: Here is the SQL from Current Year Summary followed by SQL from
Prior Year Summary
SELECT DISTINCTROW
[Qry:_jbh_InvoiceTotal

ayCurrentYear].DayofMonthCurrent,
Sum([Qry:_jbh_InvoiceTotal

ayCurrentYear].CurrentYrInvoiceAmount) AS
SumOfCurrentYrInvoiceAmount
FROM [Qry:_jbh_InvoiceTotal

ayCurrentYear]
GROUP BY [Qry:_jbh_InvoiceTotal

ayCurrentYear].DayofMonthCurrent;
SELECT DISTINCTROW [Qry:_jbh_InvoiceTotal

ayPriorYear].DayofMonthPrior,
Sum([Qry:_jbh_InvoiceTotal

ayPriorYear].PriorYrInvAmount) AS
SumOfPriorYrInvAmount
FROM [Qry:_jbh_InvoiceTotal

ayPriorYear]
GROUP BY [Qry:_jbh_InvoiceTotal

ayPriorYear].DayofMonthPrior;
I don't know where your "Option 1" and "Option 2" come from; "Option 2"
looks like the only thing we've discussed so far. If you have the two
queries you identified as "Current Year Summary" and "Prior Year Summary",
then to get a full comparison you're going to need a union of two sets:
first, all the records from [Current Year Summary] (whether they have
matches in [Prior Year Summary] or not), and second, any records from [Prior
Year Summary] that don't have matches in [Current Year Summary]. The SQL
for the first set would be like this:
SELECT
DayOfMonthCurrent As DayOfMonth,
SumOfCurrentYrInvoiceAmt As CurrentYrAmt,
Nz(SumOfPriorYrsInvoiceAmt, 0) As PriorYrAmt,
SumOfCurrentYrInvoiceAmt - Nz(SumOfPriorYrsInvoiceAmt, 0)
AS Comparison
FROM
[Current Year Summary]
LEFT JOIN
[Prior Year Summary]
ON DayOfMonthCurrent = DayOfMonthPrior;
The SQL for the second set would be like this:
SELECT
DayOfMonthPrior As DayOfMonth,
0 As CurrentYrAmt,
SumOfPriorYrsInvoiceAmt As PriorYrAmt,
-SumOfPriorYrsInvoiceAmt AS Comparison
FROM
[Prior Year Summary]
LEFT JOIN
[Current Year Summary]
ON DayOfMonthPrior = DayOfMonthCurrent
WHERE
DayOfMonthCurrent Is Null;
So the union of these sets will be given by this SQL:
SELECT
DayOfMonthCurrent As DayOfMonth,
SumOfCurrentYrInvoiceAmt As CurrentYrAmt,
Nz(SumOfPriorYrsInvoiceAmt, 0) As PriorYrAmt,
SumOfCurrentYrInvoiceAmt - Nz(SumOfPriorYrsInvoiceAmt, 0)
AS Comparison
FROM
[Current Year Summary]
LEFT JOIN
[Prior Year Summary]
ON DayOfMonthCurrent = DayOfMonthPrior
UNION ALL
SELECT
DayOfMonthPrior As DayOfMonth,
0 As CurrentYrAmt,
SumOfPriorYrsInvoiceAmt As PriorYrAmt,
-SumOfPriorYrsInvoiceAmt AS Comparison
FROM
[Prior Year Summary]
LEFT JOIN
[Current Year Summary]
ON DayOfMonthPrior = DayOfMonthCurrent
WHERE
DayOfMonthCurrent Is Null
ORDER BY DayOfMonth;
All of that is "air SQL", and completely untested, but something like that
ought to do the trick.
I see in your "Option 1" that you are introducing the idea of grouping by
Client. You didn't mention that before, and it would make things a bit more
complicated than the simple case above. Because I don't know what it is you
really want to do, I'm not going to get into that now.
By the way, the names you've given to your queries, incorporating as they do
nonstandard characters such as ":" and " ", make the SQL much more
cumbersome to work with. If you have any control of the matter, I strongly
recommend you revise these names.