Re: SQL conditional UPDATE
| From: | Derek Paterson | Date: | Thu, 12 Oct 2000 14:30:29 +0000 |
| Subject: | Re: SQL conditional UPDATE | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3555@lists.php.net to get a copy of this message | ||
Thanks, but I can't use PHP on this database just yet - that's why I need
the SQL to have conditional updates - at the moment I'm on SQL update query
number 7 to try to get round this. The database is developed elsewhere and
I know I'm going to have to redo this at least another twice before I can
let PHP loose on it.
Derek
----- Original Message -----
From: "Greg Donald" <greg@destiney.com>
To: "Derek Paterson" <d.paterson@craneware.com>; "PHP Database List"
<php-db@lists.php.net>
Sent: Thursday, October 12, 2000 3:18 PM
Subject: RE: [PHP-DB] SQL conditional UPDATE
> > Is there any way within one SQL query to Update to different values
> > dependant on conditions. I've guessed at subqueries but cannot
> > get my head
> > round the syntax and web advice differs dependant on source.
> > eg.
> > UPDATE table SET field1 = "valuea" WHERE condition1 ELSE field1 =
"valueb"
>
> $sql = "UPDATE table SET field1 = 'valuea' ";
>
> if($condition1){
> $sql .= "where condition1 == 'some_value';
> } else {
> $sql .= "where condition2 == 'some_other_value';
> }
>
> --Greg