WeimanIT
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}
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}
set t1.date1=iif(t1.type="A",t 2.date1,ii f(t1.type= "B",t2.dat e2,iif(t1. type="C",t 2.date3,t1 .date1)))
IIF(table1.type="A",table2 .Date1,IIF (table1.ty pe="B",tab le2.Date2, IIF(table1.type="C",table2 .Date3,NUL L)))
JimD.
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)
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)
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?
ASKER
I'm trying to do an update query.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.