List:General Discussion« Previous MessageNext Message »
From:Steve Edberg Date:December 9 2001 5:17am
Subject:Re: Can this be done?
View as plain text  
How about

    UPDATE
       myTable
    SET
       DueField = 0,
       StatusField = if(StatusField='O', 'C', StatusField)
    WHERE
       PrimaryKeyField = 'XYZXYZ'

See

    http://www.mysql.com/doc/C/o/Control_flow_functions.html

for more info on IF() function.

	-steve



At 12:41 PM -0600 12/7/01, Chris Boget wrote:
>Is there a way to do this?  If so, I've not been able to
>find it in the documentation...
>
>I have 3 fields:
>
>PrimaryKeyField
>StatusField
>DueField
>
>I want to update the DueField to 0 (zero) where the
>PrimaryKeyField = "XYZXYZ".  I also want to update
>the StatusField for those records to be equal to "C"
>when it's equal to "O" but not any other value.  Is there
>a way to do this all in one query?
>
><pseudocode>
>
>UPDATE myTable SET
>DueField = 0,
>( StatusField = "C" WHEN StatusField = "O")
>WHERE PrimaryKeyField = "XYZXYZ";
>
></pseudocode>
>
>Can something like that be done?
>
>Chris
>


-- 
+------------------------------------------------------------------------+
| Steve Edberg                                      sbedberg@stripped |
| University of California, Davis                          (530)754-9127 |
| Programming/Database/SysAdmin               http://pgfsun.ucdavis.edu/ |
+------------------------------------------------------------------------+
| "Restriction of free thought and free speech is the most dangerous of  |
| all subversions. It is the one un-American act that could most easily  |
| defeat us."                                                            |
|                 - Supreme Court Justice (1939-1975) William O. Douglas |
+------------------------------------------------------------------------+
Thread
Can this be done?Chris Boget7 Dec
  • Re: Can this be done?Steve Edberg9 Dec
RE: Can this be done?Gregert Johnson7 Dec