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

Multi IIF statement 2

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
US
I need to write an IIF statement for following code:

(
If Instr('abcdQ1','Q1')>0 then (select q1 from tableA),
If instr ('abcdQ2','Q2')>0 then (Select q2 from tableA)
Else (select q5 from tableA)
end if
) as Q

Is it possible to wrtie multip IIF statements in Access 2003?
thanks.
 
IIf([field name 1] Like '%Q1%', [q1],
IIf([field name 2] Like '%Q2%', [q2], [q5])) AS Q

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

hi yehong,

Since your example uses literals in the Instr function, it is ALWAYS True.

What FIELD do you want to examine instead? Like this???
Code:
Select....
iif(Instr([WhatField],'Q1')>0,A.q1,iif(Instr([WhatField],'Q2')>0,A.q2,A.q5)) as 'Q' .....
From TableA A


Skip,

[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue]
 
OOps, you may have to replace all % by *
Will one day be JetSQL more ANSI compliant ...
 
The 'WhatField' string is like:
'ABCD_Q1'
'ABCD_Q2'
'ABCD_Q3'
'ABCD_Q4'
'ABCD_Q5'...
This string is the value of a cobo box on a form. So when a user selects this value, in the background my IIF query will kick in.
 
Like this ?
SELECT ...
IIf([Forms]![name of mainform]![name of combo] Like '*Q1',[q1],
IIf([Forms]![name of mainform]![name of combo] Like '*Q2',[q2],
IIf([Forms]![name of mainform]![name of combo] Like '*Q3',[q3],
IIf([Forms]![name of mainform]![name of combo] Like '*Q4',[q4],
[q5])))) AS Q
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top