?
Solved

Using IIF and dateadd in access query.

Posted on 2008-10-09
7
Medium Priority
?
634 Views
Last Modified: 2013-11-27
I am continuing to write sql for my database and have encountered another question.

This is what I have:

FRT Due: IIf([DATE_ESCALATED]<=[DESIRED_DD],[DESIRED_DD]),IIF( [DATE_ESCALATED] > [DUE_SCHED_DATE] ,DateAdd("H",3, [DATE_ESCALATED] ), [DUE_SCHED_DATE]

This is what the excel looks like and it works =IF(F5<=H5,H5,(IF(F5>G5,F5+3,G5))), but I want this to work in an access query.

I have attache a sample of the excel book below.

Thanks
snipet.xls
0
Comment
Question by:jclem1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 22682061
Are you putting the closing ) on the query?

What error are you getting on Access query?

jppinto
0
 
LVL 44

Expert Comment

by:GRayL
ID: 22682066
FRT Due: IIf([DATE_ESCALATED]<=[DESIRED_DD],[DESIRED_DD]),IIF( [DATE_ESCALATED] > [DUE_SCHED_DATE] ,DateAdd("H",3, [DATE_ESCALATED]), [DUE_SCHED_DATE] )

A closing parenthesis??
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 600 total points
ID: 22682070
What error or bad result are you getting.  The Excel version is adding 3 days and you are adding hours.

http://www.techonthenet.com/access/functions/date/dateadd.php
FRT Due: IIf([DATE_ESCALATED]<=[DESIRED_DD],[DESIRED_DD],IIF( [DATE_ESCALATED] > [DUE_SCHED_DATE] ,DateAdd("d",3, [DATE_ESCALATED] ), [DUE_SCHED_DATE])

Open in new window

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 11

Expert Comment

by:LambertHeenan
ID: 22682104
FRT Due: IIf([DATE_ESCALATED]<=[DESIRED_DD],[DESIRED_DD],IIF( [DATE_ESCALATED] > [DUE_SCHED_DATE] ,DateAdd("H",3, [DATE_ESCALATED]) , [DUE_SCHED_DATE] ))

It's all about the brackets!

In general IIF works like this

IIF(SomeCondition, AnswerIfTrue, AnswerIfFalse)

Here is the solution broken up so you can seethe parts...

FRT Due: IIf(
{here is the condition}   [DATE_ESCALATED]<=[DESIRED_DD],
{the answer if the condition is TRUE} [DESIRED_DD],
{the answer id the condition is FALSE - a nested IIF} IIF(
{nested IIF condition } [DATE_ESCALATED] > [DUE_SCHED_DATE] ,
{ nested IFF true answer} DateAdd("H",3, [DATE_ESCALATED]) ,
{ nested IIF False answer} [DUE_SCHED_DATE] )
) {close parentheses on the outer IIF }
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 1400 total points
ID: 22682117
good spot mwvisa1. he answer adding 3 days would be

FRT Due: IIf([DATE_ESCALATED]<=[DESIRED_DD],[DESIRED_DD],IIF( [DATE_ESCALATED] > [DUE_SCHED_DATE] ,DateAdd("d",3, [DATE_ESCALATED]) , [DUE_SCHED_DATE] ))
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22682220
@LambertHeenan, thanks for cleaning up.  I corrected the bracket problems I saw, but forgot one of the end ones myself. :)
0
 
LVL 1

Author Closing Comment

by:jclem1
ID: 31504812
Thank you both very much, very helpful and very quick!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question