Rusty3 Posted August 25, 2010 Share Posted August 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211733-update-if-null/ Share on other sites More sharing options...
kickstart Posted August 25, 2010 Share Posted August 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211733-update-if-null/#findComment-1103710 Share on other sites More sharing options...
Rusty3 Posted August 25, 2010 Author Share Posted August 25, 2010 Thanks for the idea kickstart, let me test it out... Quote Link to comment https://forums.phpfreaks.com/topic/211733-update-if-null/#findComment-1103714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.