Re: UPDATE IF

From: Date: Mon, 14 Mar 2011 16:42:53 +0000
Subject: Re: UPDATE IF
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-47721@lists.php.net to get a copy of this message
On 14 March 2011 15:42, Gary <gpaul@paulgdesigns.com> wrote: > I have a table in a mysql db that has 3 columns that I want to insert > (update) data if the row&column is empty (IS NULL).  However I want to start > at the first column, if this column is not null, then move to insert the > data into column 2, if that is empty, then insert data into column 3. > > I have been looking over the manual and boards but am not finding a > solution. > > Can anyone point me in the right direction. > > -- > Gary > > > > __________ Information from ESET Smart Security, version of virus signature database 5952 > (20110314) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > You would have to code it. I'm not a mysql guru (MSSQL is what I use), but ... UPDATE Table SET Column3 = CASE WHEN Column3 IS NULL AND Column2 IS NOT NULL AND Column1 IS NOT NULL THEN Value ELSE Column3 END, Column2 = CASE WHEN Column2 IS NULL AND Column1 IS NOT NULL THEN Value ELSE Column2 END, Column1 = CASE WHEN Column1 IS NULL THEN Value ELSE Column1 END WHERE IDColumn = ID something like that? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.db (#47721) next »