Jump to content

Using CASE in a query..help


itzleijae

Recommended Posts

The goal is to search two similar tables for a single line of data.

UPDATE
    regusers_test AS rt
INNER JOIN
    alt_toon_test AS att
ON
    att.`toonname` = rt.`toonname`
SET
    rt.`server` = CASE WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' ELSE rt.`server`
    att.`server` = CASE WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' ELSE att.`server`
WHERE
(
    rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon'
)
OR
(
    att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon'
)

But i keep getting:

 

 

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 'att.'server'=Case When att.'username'='$user'...

 

 

I did a lot of google searches over the weekend and couldn't find a solution. Hopefully someone here knows what's up.

Edited by itzleijae
Link to comment
Share on other sites

You're missing the END for the case statement, as well as your comma between fields.

 

UPDATE regusers_test AS rt
INNER JOIN alt_toon_test AS att ON att.`toonname` = rt.`toonname`
SET
	rt.`server` = CASE 
		WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' 
		ELSE rt.`server`
	END
	, att.`server` = CASE 
		WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' 
		ELSE att.`server`
	END
WHERE
	(rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon')
	OR (att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon')
Link to comment
Share on other sites

You're missing the END for the case statement, as well as your comma between fields.

 

UPDATE regusers_test AS rt
INNER JOIN alt_toon_test AS att ON att.`toonname` = rt.`toonname`
SET
	rt.`server` = CASE 
		WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' 
		ELSE rt.`server`
	END
	, att.`server` = CASE 
		WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' 
		ELSE att.`server`
	END
WHERE
	(rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon')
	OR (att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon')

haha i derped. Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.