BeardedSith
Member
- Local time
- Today, 04:04
- Joined
- Feb 5, 2020
- Messages
- 73
Hey all!
@plog has done some amazing work helping me fumble through this SQL mess. Now that he's solved the most pressing issues with my queries, I was hoping I could nab some help with trying to nest them all into one query I can call on demand. Spending roughly ten minutes on this I got myself so confused I had to put it down
. Here are my multiple SQL statements:
Working backwards in the chain of queries:
qryEligibility - what I would prefer to have everything else merged into:
All of these other queries (four in total) are support for the query above:
sqryCalc3
sqryCalc2
sqryCalc1
sqryCalc0
BACKGROUND:
These queries are intended to pull and calculate eligibility based on several parameters set forth in tblOptions. These queries use tbPurchases, tblRewards (yes, I left out an "L" in tbPurchases), and tblOptions which only has a single row for options within the database.
I would prefer the ability to conduct all of these calculations within a single query that I can call when necessary. If anyone would like example data, I can provide that as requested.
Thank you in advance!
@plog has done some amazing work helping me fumble through this SQL mess. Now that he's solved the most pressing issues with my queries, I was hoping I could nab some help with trying to nest them all into one query I can call on demand. Spending roughly ten minutes on this I got myself so confused I had to put it down

Working backwards in the chain of queries:
qryEligibility - what I would prefer to have everything else merged into:
Code:
SELECT sqryCalc3.CustomerID, IIf([sqryCalc3]![SumOfPurchaseAmount]>[tblOptions]![MaxIssue],[tblOptions]![MaxIssue],[sqryCalc3]![SumOfPurchaseAmount]) AS RealAmount, sqryCalc3.RealDate, IIf([sqryCalc3]![NumPurchases]>[tblOptions]![NumPurchases],1,0) AS IsEligible
FROM tblOptions, sqryCalc3
WHERE (((IIf([sqryCalc3]![NumPurchases]>[tblOptions]![NumPurchases],1,0))=1));
All of these other queries (four in total) are support for the query above:
sqryCalc3
Code:
SELECT sqryCalc1.CustomerID, Count(sqryCalc2.MemberID) AS NumPurchases, Sum(Nz([DailyPurchaseTotal],0)) AS SumOfPurchaseAmount, sqryCalc1.RealDate
FROM sqryCalc1 LEFT JOIN sqryCalc2 ON sqryCalc1.CustomerID = sqryCalc2.MemberID
GROUP BY sqryCalc1.CustomerID, sqryCalc1.RealDate;
sqryCalc2
Code:
SELECT sqryCalc0.MemberID, sqryCalc0.DatePurchase, Sum(sqryCalc0.PurchaseAmount) AS DailyPurchaseTotal
FROM sqryCalc0 INNER JOIN sqryCalc1 ON sqryCalc0.MemberID = sqryCalc1.CustomerID
WHERE (((sqryCalc0.DatePurchase)>[RealDate] And (sqryCalc0.DatePurchase)>CDate("1/1/" & Year(Date()))))
GROUP BY sqryCalc0.MemberID, sqryCalc0.DatePurchase;
sqryCalc1
Code:
SELECT tblRewards.CustomerID, IIf(Max([tblRewards]![IssueDate]<DateSerial(Year(Now()),1,1)),DateSerial(Year(Now()),1,1),Max([tblRewards]![IssueDate])) AS RealDate
FROM tblRewards
GROUP BY tblRewards.CustomerID;
sqryCalc0
Code:
SELECT tbPurchases.MemberID, DateValue([PurchaseDate]) AS DatePurchase, tbPurchases.PurchaseAmount
FROM tbPurchases;
BACKGROUND:
These queries are intended to pull and calculate eligibility based on several parameters set forth in tblOptions. These queries use tbPurchases, tblRewards (yes, I left out an "L" in tbPurchases), and tblOptions which only has a single row for options within the database.
I would prefer the ability to conduct all of these calculations within a single query that I can call when necessary. If anyone would like example data, I can provide that as requested.
Thank you in advance!