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}



LVL 1
WeimanITAsked:
Who is Participating?
 
LowfatspreadConnect With a Mentor Commented:
you tried this?

update table1
set t1.date1=iif(t1.type="A",t2.date1,iif(t1.type="B",t2.date2,iif(t1.type="C",t2.date3,t1.date1)))
from table1 as t1
,table2 as t2
where t1.columnx = t2.columnx

... how are you joining table1 and table2?
0
 
LowfatspreadCommented:
set t1.date1=iif(t1.type="A",t2.date1,iif(t1.type="B",t2.date2,iif(t1.type="C",t2.date3,t1.date1)))
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
IIF(table1.type="A",table2.Date1,IIF(table1.type="B",table2.Date2, IIF(table1.type="C",table2.Date3,NULL)))
JimD.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
Patrick MatthewsCommented:
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)
0
 
WeimanITAuthor Commented:
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.  
0
 
Patrick MatthewsCommented:
Are you trying to do an UPDATE, or a SELECT?
0
 
WeimanITAuthor Commented:
I'm trying to do an update query.
0
All Courses

From novice to tech pro — start learning today.