SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with update case

    can someone help me with this query?
    Code:
    UPDATE punch SET punchval = 
    			            CASE
    			             WHEN punchval > 10 
    						   THEN punchval - 11
    				     WHEN punchval <= 0 
    						   THEN punchval +(-10)
    						 ELSE punchval
                     END	
    			WHERE 
    				pc = $WASHES_ROW[pc]
    				AND EXISTS (
    					SELECT *
    					FROM tvalues 
    						JOIN lookups ON lookups.ttype = tvalues.ttype 
    					WHERE tvalues.transid2 = $WASHES_ROW[transid] AND lookups.ttype IN ('4980','4981')
    				)
    		";
    the first case works it does update the punchval field if punchval < 10 then it deducts 11 from punchval, but i can't seem to get it to work when punchval is >=0. it should take punchval + (-10) to punchval field. please help...this is the first time i've used case in my update statement.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    change <= in your code to >= as described in your explanation
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry my explanation is wrong been taking medication so i haven't been thinking straight. i mistyped. it should be when punchval <= 0 then it should execute punchval + (-10) or when punchval > 10 then punchval-11. the query is correct the explanations are wrong.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    i see
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •