Reputation: 1869
I have a complex join part of which includes a CASE WHEN to construct a URL. This worked fine for part of the construction but I'm running into issues doing CASE WHEN when each CASE includes a Concat. Any of the several CASES I have works on its own with
CASE wHEN T1.Name='X' THEN Concat('A',T1.Field1)
ELSE ''
END
OR
CASE WHEN T1.Name='Y' THEN Concat('B',T1.Field2)
ELSE ''
END
Once I try to do
CASE WHEN T1.Name='X' THEN Concat('A',T1.Field1)
CASE WHEN T1.Name='X' THEN Concat('A',T1.Field2)
ELSE ''
END
I get an error like
[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 T1.Name='X' THEN Concat' at line 5
Upvotes: 1
Views: 252
Reputation: 2368
You are trying to start another CASE
function inside the first. Remove the second CASE
and it should work:
CASE WHEN T1.Name='X' THEN Concat('A',T1.Field1)
WHEN T1.Name='Y' THEN Concat('A',T1.Field2)
ELSE ''
END
Upvotes: 1