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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with IIF statement 2

Status
Not open for further replies.
Feb 4, 2009
137
US
I have 3 fields with yes/no with value (0/-1)with the fields named "nt1", "nt2", and "nt3".

In a query i would like to combine all those 3 yes/no field with 1 field only. I like to named the new field in query "ComNt". If either 3 of those yes/no has value equal "-1" then, then "ComNt" =1, else just leave the value equal blank.

I don't know how to write the IIF statement,please help.
I'm very appreciated. Thanks.
 
IIF statements are fairly simple: IIF(condition, value if true, value if false). Here is one option for yours:

ComNt: IIf([nt1]=-1 Or [nt2]=-1 Or [nt3]= -1, 1, 0)

Another option is to use a nested IIF, where "value if false" becomes a new IIF:

ComNt: IIf([nt1]= -1, 1, IIf([nt2]= -1, 1, IIf([nt3]= -1, 1, 0)))

Hope this helps.

 
SELECT IIf(nt1 OR nt2 OR nt3, 1, Null) AS comNt
FROM yourTable

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks tmputman and PHV for your kind response. They're both worked like charm.
Again, thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top