J
Jenny Barker
I'm trying to create a query to summarize records based on dates. In one
column, I want the sum of all expenditures before the beginning of the month,
in the other column I want the sum of all expenditures within the month. I
think a union query is the way to go, but it's not giving me the results I
expect. Instead of the 4 columns for one record I want to see (LastName,
FirstName, PriorExp, CurrentExp) I get 3 columns (LastName, FirstName,
PriorExp) but 2 records (at least the math is right). This is my first foray
into union queries so I may possibly have some sort of syntax error - perhaps
someone would be kind enough to help. Thanks in advance.
SELECT tblClients.LastName, tblClients.FirstName,
Sum(tblExpenditures.PaymentAmount) AS PriorExp
FROM tblClients INNER JOIN tblExpenditures ON tblClients.LoanNumber =
tblExpenditures.LoanNumber
WHERE (((tblExpenditures.PaymentDate)<[forms]![frmCurrentMonth]![BegDate]))
GROUP BY tblClients.LastName, tblClients.FirstName
UNION SELECT tblClients.LastName, tblClients.FirstName,
Sum(tblExpenditures.PaymentAmount) AS CurrentExp
FROM tblClients INNER JOIN tblExpenditures ON tblClients.LoanNumber =
tblExpenditures.LoanNumber
WHERE (((tblExpenditures.PaymentDate) Between
[forms]![frmCurrentMonth]![BegDate] And [forms]![frmCurrentMonth]![EndDate]))
GROUP BY tblClients.LastName, tblClients.FirstName;
column, I want the sum of all expenditures before the beginning of the month,
in the other column I want the sum of all expenditures within the month. I
think a union query is the way to go, but it's not giving me the results I
expect. Instead of the 4 columns for one record I want to see (LastName,
FirstName, PriorExp, CurrentExp) I get 3 columns (LastName, FirstName,
PriorExp) but 2 records (at least the math is right). This is my first foray
into union queries so I may possibly have some sort of syntax error - perhaps
someone would be kind enough to help. Thanks in advance.
SELECT tblClients.LastName, tblClients.FirstName,
Sum(tblExpenditures.PaymentAmount) AS PriorExp
FROM tblClients INNER JOIN tblExpenditures ON tblClients.LoanNumber =
tblExpenditures.LoanNumber
WHERE (((tblExpenditures.PaymentDate)<[forms]![frmCurrentMonth]![BegDate]))
GROUP BY tblClients.LastName, tblClients.FirstName
UNION SELECT tblClients.LastName, tblClients.FirstName,
Sum(tblExpenditures.PaymentAmount) AS CurrentExp
FROM tblClients INNER JOIN tblExpenditures ON tblClients.LoanNumber =
tblExpenditures.LoanNumber
WHERE (((tblExpenditures.PaymentDate) Between
[forms]![frmCurrentMonth]![BegDate] And [forms]![frmCurrentMonth]![EndDate]))
GROUP BY tblClients.LastName, tblClients.FirstName;