Link to home
Start Free TrialLog in
Avatar of WeimanIT
WeimanITFlag for Afghanistan

asked on

IF/THEN/ELSE Microsoft Access query statement

I have the following if then else statement written out.  I need to script this in an Access query.  Am I able to type this into a single statement or do I have to do 3 separate statements in the query for each table2 date?      

if {table1.type} = "A" then {table1.Date1} = {table2.Date1} else
if {table1.type} = "B" then {table1.Date1} = {table2.Date2} else
if {table1.type} = "C" then {table1.Date1} = {table2.Date3}



Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

set t1.date1=iif(t1.type="A",t2.date1,iif(t1.type="B",t2.date2,iif(t1.type="C",t2.date3,t1.date1)))
IIF(table1.type="A",table2.Date1,IIF(table1.type="B",table2.Date2, IIF(table1.type="C",table2.Date3,NULL)))
JimD.
No points for this, please :)

I get confused by nested IIf, and so I prefer Switch:

Switch(table1.type = "A", table2.Date1, table1.type = "B", table2.Date2, table1.type = "C", table2.Date3, True, Null)
Avatar of WeimanIT

ASKER

I tried the first two suggestions and get a zero value.  I tried the switch formula and All i get is the value of table2.date1 as a result.  I need the value of table2.date1 to get the date from table1.date1 if table1.type = A.  The switch statement doesn't mention table1.date1.  
Are you trying to do an UPDATE, or a SELECT?
I'm trying to do an update query.
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial