UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Or Is Null In Iif Statement    
 
   
jrflanagan
post Nov 29 2011, 09:52 AM
Post #1

New Member
Posts: 12



I am having some trouble getting a query to count null values in the following statement.

SELECT Date.DateKey, Count(*) AS ActiveReqs
FROM Reqs, Date
WHERE (((Reqs.[Job Added])<=([Date].[DateKey]) And (Reqs.[Job Added])>#10/20/2010#) AND ((Reqs.ClosedDate)>=IIf([Reqs].[Open/Closed]=1,#10/20/2010#,[Date].[DateKey])))
GROUP BY Date.DateKey;


The IIF statement is where I'm getting hung up......If true, I would like it to count all ClosedDate values greater than or equal to 10/20/2010 including null values. If False, I would like it to count only ClosedDate values greater than or equal to the DateKey excluding nulls.

I have tried including "Or Is Null" after #10/20/2010# (in the true part of the IIF statement) but with no luck...the odd part is that if I include Or Is Null after [Date].[DateKey] (in the false part of the IIF statement) it does count the null values in the False part of the statement.

Any suggestions on how to get this query to work properly...and secondly why does the Or Is Null work in the false part of the statement above?

Thank you!

Jason
Go to the top of the page
 
+
theDBguy
post Nov 29 2011, 10:10 AM
Post #2

Access Wiki and Forums Moderator
Posts: 48,642
From: SoCal, USA



Hi Jason,

(IMG:style_emoticons/default/welcome2UA.gif)

What version of Access are you using? Knowing the Access version may help us determine a more appropriate response to your question.

Maybe you could try a different approach. For example:

...
WHERE Reqs.[Job Added]<=[Date].[DateKey] And Reqs.[Job Added]>#10/20/2010# AND ((Reqs.[Open/Closed]=1 AND (Reqs.ClosedDate >=#10/20/2010# OR Reqs.ClosedDate Is Null)) OR (Reqs.ClosedDate>=[Date].[DateKey]))
...

(untested)
Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
jrflanagan
post Nov 29 2011, 10:14 AM
Post #3

New Member
Posts: 12



I'll play around with that. Thanks.

I'm on Access 2010
Go to the top of the page
 
+
jrflanagan
post Nov 29 2011, 10:33 AM
Post #4

New Member
Posts: 12



That worked! Thank you! I should have posted yesterday instead of spending a good chunk of the afternoon searching the web for a solution and coming up with nothing. Thanks again!
Go to the top of the page
 
+
theDBguy
post Nov 30 2011, 01:23 AM
Post #5

Access Wiki and Forums Moderator
Posts: 48,642
From: SoCal, USA



Hi,

QUOTE (jrflanagan @ Nov 29 2011, 08:33 AM) *
That worked! Thank you! I should have posted yesterday instead of spending a good chunk of the afternoon searching the web for a solution and coming up with nothing. Thanks again!

(IMG:style_emoticons/default/yw.gif)

Glad to hear you got it to work. Good luck with your project.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 11:59 PM

Tag cloud: