SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    CASE WHEN wrong syntax

    Hi guys and good weekend for all.

    I can not working this query update with CASE WHEN... What is wrong in this syntax?
    I hope your appreciated help.
    Saludos!

    Code:
    UPDATE tbl_upd t
    JOIN(
    	SELECT
    		(
    			FIRST SELECT
    				...) + (LAST SELECT ...) output1)output2
    			SET CASE
    			WHEN LENGTH(strVariables)= 2 THEN
    				t.FieldUpdate1 = output2.output1
    			WHERE
    				xCodes = CONCAT(strVariables, '12')
    			ELSE
    				t.FieldUpdate2 = output2.output1
    			WHERE
    				xCodes = strVariables
    			END;
    
    
    
    
    
    [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN 
              LENGTH(strVariables) = 2 THEN t.FieldUpdate1 = output2.output1 WHERE ' at line 41

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Miguel61 View Post
    What is wrong in this syntax?
    you can only SET a column, you cannot SET a CASE expression
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    thank you!


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
  •