UPDATE IF
am 14.03.2011 16:42:46 von gary
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
Re: UPDATE IF
am 14.03.2011 17:42:53 von Richard Quadling
On 14 March 2011 15:42, Gary 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 signatu=
re 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 =3D CASE
WHEN
Column3 IS NULL
AND
Column2 IS NOT NULL
AND
Column1 IS NOT NULL
THEN
Value
ELSE
Column3
END,
Column2 =3D CASE
WHEN
Column2 IS NULL
AND
Column1 IS NOT NULL
THEN
Value
ELSE
Column2
END,
Column1 =3D CASE
WHEN
Column1 IS NULL
THEN
Value
ELSE
Column1
END
WHERE
IDColumn =3D ID
something like that?
--=20
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php