SQL Update Statement with 'If' condition

I've created an update statement in MS Access as follows:

     UPDATE myTable SET myDateColumn = IIf(1=1, Null, Now());

which works, setting myDateColumn to Null. If I change the expression in the 'IIf' statement to 1=2 then the column updates to todays date.

I need to re-write this statement for use in a vb.net application.

Can someone provide the correct syntax?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Kyle AbrahamsSenior .Net DeveloperCommented:
UPDATE myTable SET myDateColumn = case when 1=1 then  Null else getdate() end
ste5anSenior DeveloperCommented:
See IIF() (SQL Server 2012+):

UPDATE  myTable
SET     myDateColumn = IIF(1 = 1, NULL, GETDATE());

Open in new window

käµfm³d 👽Commented:
What do you mean by, "...for use in a vb.net application." Are you looking for the VB.NET equivalent of an IIF, or are you saying you want to invoke that query from VB.NET...or something else?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tim313Author Commented:
I'm looking for the VB.NET equivalent of an IIF.
Kyle AbrahamsSenior .Net DeveloperCommented:
as long as you're using 2008 or above you should be able to call just if:

if (1=1, Nothing, DateTime.Now)

however if you're executing it against a database you would use the SQL version I posted with the case statement.
Tim313Author Commented:
I found the answer:

UPDATE tblSalesOrderTracking SET DueDate = IIf(1=1, " & "NULL" & ", #" & Now.ToShortDateString & "#)

Changes 'DueDate' from Null to todays date based on expression in IIf statement.

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
ste5anSenior DeveloperCommented:
Nope. Now.ToShortDateString depends on the locals, while an fixed format (en-US) works always.
Tim313Author Commented:
Found the solution myself.
ste5anSenior DeveloperCommented:
Caveat: Your solution depends on the locales used by the application. Use an explicit format.
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
Query Syntax

From novice to tech pro — start learning today.