Jump to content

Update IF NULL


Rusty3

Recommended Posts

Hello. Any way to do this on a single Update query? I mean I have rows with many many columns and would like to update only the values that are NULL. Can I use IFNULL?

 

var1 = NULL

var2 = C

 

UPDATE myvariables SET var1=A, var2=B (...) WHERE id=100

 

I want var1 to be updated, but var2 to be left intact.

 

I am sure this is recurring problem.

 

Thanks for any clue.

Link to comment
Share on other sites

Hi

 

Not sure as never tried it on an update, but would think you could use a switch statement

 

Following isn't tested but might give you an idea.

 

UPDATE myvariables 
SET var1 = CASE var1 WHEN NULL THEN A ELSE VAR1 END,
var2 = CASE var2 WHEN NULL THEN B ELSE VAR2 END
WHERE id=100

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.