Multiple If Then Query Issues (1 Viewer)

sparklegrrl

Registered User.
Local time
Today, 20:28
Joined
Jul 10, 2003
Messages
124
Good morning,

I'm having trouble with what I think should be a simple query but I'm pulling my hair out. All I need is employees by month.

January for example. Shouldn't I be able to query employees who have a null term date and hire date prior to 1/31/20?

Thanks in advance!
 

jdraw

Super Moderator
Staff member
Local time
Today, 15:28
Joined
Jan 23, 2006
Messages
15,395
Shouldn't I be able to query employees who have a null term date and hire date prior to 1/31/20?
Please provide a little more context. What have you tried? Result?
 

sparklegrrl

Registered User.
Local time
Today, 20:28
Joined
Jul 10, 2003
Messages
124
JAN20: IIf([TERMDATE] Is Null And [HIREDATE]<1/31/2020,1,0)

Every line is coming up 0?
 

June7

AWF VIP
Local time
Today, 11:28
Joined
Mar 9, 2014
Messages
5,492
Try using # delimiters:

JAN20: IIf([TERMDATE] Is Null And [HIREDATE]<#1/31/2020#,1,0)
 

jdraw

Super Moderator
Staff member
Local time
Today, 15:28
Joined
Jan 23, 2006
Messages
15,395
Try
JAN20: IIf(IsNull([TERMDATE]) AND [HIREDATE]<#1/31/2020#,1,0)
 

plog

Banishment Pending
Local time
Today, 14:28
Joined
May 11, 2011
Messages
11,668
Seems to be working! TY!

Is it? Put some test data in and see if someone who was hired 1/1/2020 and terminated 3/3/2020 shows up correctly.
 

plog

Banishment Pending
Local time
Today, 14:28
Joined
May 11, 2011
Messages
11,668
Thinking about it more, your entire approach is probably incorrect. This hard coding dates method is fine if you want to run this report just once. My guess is it will be run monthly and will be run in future years as well. If so, you need to make it so that this thing works any date you run it without having to edit all the calculations.

Will this be run in 2021?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:28
Joined
Feb 28, 2001
Messages
27,309
Shouldn't I be able to query employees who have a null term date and hire date prior to 1/31/20?

IIF shouldn't even be a part of this.

SELECT * FROM employees WHERE ( NZ(TermDate,0) = 0 ) AND ( HireDate < #31-Jan-2020# ) ;
 

June7

AWF VIP
Local time
Today, 11:28
Joined
Mar 9, 2014
Messages
5,492
Good point. But won't address possible logic flaw identified by Plog. OP needs to clarify what they want to do with terminations of Jan hires. And for that matter, any month. Is goal to list employees by their status in January or current status?

And again, Nz() is a VBA function and doesn't really change what Is Null was doing.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:28
Joined
Feb 28, 2001
Messages
27,309
The question (which isn't clarified by what I saw) is whether the value was truly null or whether it was 0. It would depend on how the date had been set up when the record was created, so for me the NZ is a belt-and-suspenders approach. But I agree that IsNull() works in that context.
 

June7

AWF VIP
Local time
Today, 11:28
Joined
Mar 9, 2014
Messages
5,492
Not IsNull(), that's still a VBA function, Is Null is SQL.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:28
Joined
Feb 28, 2001
Messages
27,309
Read the other part of my same comment. If the date value was 0 because of the way the empty value was processed, IS NULL won't work.
 

Users who are viewing this thread

Top Bottom