Subquery To Select Checks by Varying Age Requirements

AlexB123

Board Regular
Joined
Dec 19, 2014
Messages
194
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))
;
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,527
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:

AlexB123

Board Regular
Joined
Dec 19, 2014
Messages
194
@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)
 

Forum statistics

Threads
1,078,461
Messages
5,340,442
Members
399,375
Latest member
alwayssunny

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top