Re: SQL conditional UPDATE

From: Date: Thu, 12 Oct 2000 15:02:58 +0000
Subject: Re: SQL conditional UPDATE
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-3557@lists.php.net to get a copy of this message
Yes, that's what I've ended up doing (7 at the latest count). I've found from MS-SQL help, would you believe, that it is possible to have an UPDATE ... SET field1= (SELECT.. FROM WHERE..) WHERE .. structure but my brain hurt too much trying to work it the conditions - I think it would have had to be a double embedded SELECT. Creating a temporary table/column was another option but I've just about got the 7 individual queries written (less chance of error) and I've numbered them so I remember what order they've to be run in. Thanks anyway Derek ----- Original Message ----- From: "Richard Allsebrook" <richard.allsebrook@easysoft.com> To: "Derek Paterson" <d.paterson@craneware.com>; "PHP Database List" <php-db@lists.php.net> Sent: Thursday, October 12, 2000 3:50 PM Subject: RE: [PHP-DB] SQL conditional UPDATE > How about two queries: > > UPDATE table SET field1 = "valuea" WHERE condition1 > UPDATE table SET field1 = "valueb" WHERE NOT condition1 > > _____ > > ~ Richard Allsebrook ~ > Applications Developer and Webmaster > Easysoft Limited, No3 The Embankment, Leeds, LS1 4BJ > http://www.easysoft.com > <http://www.easysoft.com> - > http://www.cinema.com > <http://www.cinema.com> > "A computer lets you make more mistakes faster than any invention in human > history - with the possible exceptions of handguns and tequila." > > _____ > > > > > > -----Original Message----- > From: Derek Paterson [mailto:d.paterson@craneware.com] > Sent: Thursday, October 12, 2000 2:47 PM > To: PHP Database List > Subject: [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" > > I know I could build dynamic queries in PHP but this db isn't on the web > yet - trying to get it into shape to put it there. > > TIA > > Derek > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#3557) next »