Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded IIF in Query - HELP 2

Status
Not open for further replies.

elaineva

Programmer
Nov 14, 2002
35
US
I'm trying to use embedded IIF Statement in a query (first time using it) and I keep getting the error "expression you entered is missing a closing parenthesis,bracket or vertical bar". The first 2 IIF statements work great but when I add the last two - I get the error.

Can anyone tell me what's wrong??

RStatall: IIf([RStatus] Is Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0,2,IIf([EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]<5 And [SumOfRPAY]>=0 Or [EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc] Is Null And [SumOfRPAY]>=0,12,IIf([EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]>=5 And [SumOfRPAY]>=0,11, IIf([EecPayGroup]=&quot;RETIRE&quot; And [SumOfRPAY]>=0,14))

 
You have 4 inbedded IIF statements and only 2 closing parens. You need 2 more.
The last IIF statement is missing a &quot;False&quot; statement.
 


missing two &quot;)&quot;'s at the end. Also, you could do with putting a final &quot;&quot; in at the end of the last IIF, because if it's false, I don't know wha tit would put (maybe an error)

so:

try this (I have coloured the parts you need to look at):

RStatall: IIf([RStatus] Is Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0,2,IIf([EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]<5 And [SumOfRPAY]>=0 Or [EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc] Is Null And [SumOfRPAY]>=0,12,IIf([EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]>=5 And [SumOfRPAY]>=0,11,IIf([EecPayGroup]=&quot;RETIRE&quot; And [SumOfRPAY]>=0,14,&quot;&quot;))))


As a tip, this is how I normally look at IIF or IF statements if I think (or know!!) there is a problem:
Code:
IIF(
   Condition,
   True,
   False
)
and nested like this:
Code:
IIF(
   Condition,
   True,
   IIF(
      Condition,
      True,
      False
   )
)

so, for the code you supplied, I would have looked at it in this format and highlighted what I saw missing:
Code:
RStatall:

IIf(
   [RStatus] Is Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination] Is Null And [SumOfRPAY]>=0 Or [RStatus] Is Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0 Or [RStatus] Is Not Null And [EecDateOfTermination]>[YREND] And [SumOfRPAY]>=0,
   2,
   IIf(
      [EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]<5 And [SumOfRPAY]>=0 Or [EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc] Is Null And [SumOfRPAY]>=0,
      12,
      IIf(
         [EecDateOfTermination] Between [YRBEG] And [YREND] And [RVesting Svc]>=5 And [SumOfRPAY]>=0,
         11,
         IIf(
            [EecPayGroup]=&quot;RETIRE&quot; And [SumOfRPAY]>=0,
            14,
&quot;&quot;
Code:
         )
      )
)
)



Aubs
 
Thanks so much - both of you. Works like a charm!!
 
Pleasure Elaineva, thanks for the
star.gif
. ;-)

Doh 28816, Can't believe you beat me to it - I got the post as soon as it was posted! - Must be because I'm slow!!! lol



Aubs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top