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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)President / OwnerCommented:
IIF(table1.type="A",table2.Date1,IIF(table1.type="B",table2.Date2, IIF(table1.type="C",table2.Date3,NULL)))
JimD.
0
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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
LowfatspreadCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.