List:General Discussion« Previous MessageNext Message »
From:Scott Haneda Date:October 28 2005 4:22am
Subject:Re: Possible to use a conditional in this UPDATE
View as plain text  
on 10/27/05 6:34 PM, Scott Haneda at lists@stripped wrote:

> Right now, my update works as follows, and works fine, however, I want to do
> a condition to say if products.ship_status = 1 then set
> cart_test.shipping_status to 'now' else set it to 'soon'
> 
> UPDATE cart_test, products
> SET cart_test.shipping_status = products.ship_status
> WHERE products.id = cart_test.product_id AND cart_test.session_id = '5511'
> 
> Is this even possible, if so, can someone help me out a bit.
> Thanks

I think I partly got it:
UPDATE cart, products
SET cart.ship_status = IF(products.ship_status = 1, 'now', 'soon')
WHERE products.id = cart.product_id AND
cart.session_id = "5511"

However, I need a ELSE in there, I can not always assume other than '1' is
'soon', is there some way to add in a ELSE?
-- 
-------------------------------------------------------------
Scott Haneda                                Tel: 415.898.2602
<http://www.newgeo.com>                     Novato, CA U.S.A.


Thread
Possible to use a conditional in this UPDATEScott Haneda28 Oct
  • Re: Possible to use a conditional in this UPDATEScott Haneda28 Oct
    • Re: Possible to use a conditional in this UPDATEJasper Bryant-Greene28 Oct
    • Re: Possible to use a conditional in this UPDATEBrent Baisley28 Oct
      • Re: Possible to use a conditional in this UPDATEScott Haneda29 Oct
        • Re: Possible to use a conditional in this UPDATEMichael Stassen31 Oct