Subquery To Select Checks by Varying Age Requirements

AlexB123

Board Regular
Joined
Dec 19, 2014
Messages
207
Hi all,

I have a need to select all checks that fall within an age threshold determined by a client's preference. For example, one client might choose a 30 day threshold, another might choose every ninety days.

I am receiving an error: "at most one record can be returned by this subquery."

Open to any suggestions, thanks.


Code:
SELECT tblChecks.CheckID
FROM (tblChecks 
 INNER JOIN tblClients ON tblChecks.ClientID = tblClients.ClientID)
 INNER JOIN tbl_UC_AGE ON tblClients.MV_UC_AGE = tbl_UC_AGE.ID
WHERE ((tblChecks.ActionID)=2000)
AND ((tblChecks.Status)=1)
AND ((tblChecks.Check_Date)<=DATE() - (SELECT a.AGE_DAYS FROM tbl_UC_AGE a
             INNER JOIN tblClients b ON a.ID = b.MV_UC_AGE))
;
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Did you check out what this subquery is returning?

SELECT a.AGE_DAYS FROM tbl_UC_AGE a
INNER JOIN tblClients b ON a.ID = b.MV_UC_AGE

It looks like it is returning a set of every UC_age for every client. Which is probably wrong (you need a UC_age for each particular client).
Might want to just start over on this one.

Not sure what your data looks like. Probably should be okay to use a regular join, not a subquery. You should post some sample data if you are stuck - hard to write queries without knowing what is in the tables.
 
Last edited:
Upvote 0
@xenou,

Thank you for your reply. I was overthinking the problem, I just relied on the innerjoin.


Code:
SELECT tblChecks.CheckID
FROM (tblChecks 
 INNER JOIN tblClients ON tblChecks.ClientID = tblClients.ClientID)
 INNER JOIN tbl_UC_AGE ON tblClients.MV_UC_AGE = tbl_UC_AGE.ID
WHERE ((tblChecks.ActionID)=2000)
AND ((tblChecks.Status)=1)
AND ([LEFT][COLOR=#222222][FONT=Verdana]DATE() [/FONT][/COLOR][/LEFT]- (tblChecks.Check_Date)>= tbl_UC_AGE.Days)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top