RE: [PHP-DB] IFNULL used in a UPDATE

From: Date: Thu, 14 Mar 2002 00:25:00 +0000
Subject: RE: [PHP-DB] IFNULL used in a UPDATE
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-17668@lists.php.net to get a copy of this message
Hi Jane, No questions are lame. The statement you wrote down wouldn't work as IFNULL() function doesn't work the way you intended. See http://www.mysql.com/doc/C/o/Control_flow_functions.html for this.. I would accomplish it in two statements. Here it is: SELECT (@a:=(CASE box1 WHEN '' THEN NOW() ELSE box1 END)) from users; UPDATE users SET box1=@a, box2=NOW() WHERE email='tracys@yahoo.com'; I hope this helps.. Gurhan -----Original Message----- From: jane [mailto:jcheryl@excite.com] Sent: Wednesday, March 13, 2002 12:09 PM To: php-db@lists.php.net Subject: [PHP-DB] IFNULL used in a UPDATE Hello, I am new to SQL so I hope this is not a lame question. I want to UPDATE two fields ('box1' & 'box2') in table 'users'. One field I want to always set the current time. The other field I want to put the current time ONLY if it has the value NULL. Here is my attempt: UPDATE users SET IFNULL(box1 = NOW()), box2 = NOW() WHERE eMail = 'tracys@yahoo.com' Any help would be greatly appreciated. Jane. Using: MySQL 3.22.27 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#17668) next »