|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm new to MySQL, but fairly adept with MS SQL Server. I've written the following select statement that fails with a syntax error when executed in MySQL. I have referred to the MySQL manual and toyed with the syntax a bit, but with no success. I am confident its not the CONCAT, as I have used the same CONCAT syntax elsewhere with success. Any guidance would be appreciated...
SELECT CASE WHEN sq.presuf = 0 THEN concat(pl.name, ' ', sq.tag) ELSE concat( sq.tag,' ', pl.name) END as name, pl.email, pl.icq from squads sq, players pl where sq.name = pl.squadname |
|
#2
|
|||
|
|||
|
whoops...thats
SELECT CASE WHEN sq.presuf = 0 THEN concat(pl.name, ' ', sq.tag) ELSE concat( sq.tag,' ', pl.name) END as name, pl.email, pl.icq from squads as sq, players as pl where sq.name = pl.squadname |
|
#3
|
|||
|
|||
|
It's not the concat as MySQL supports that, but MySQL does not support CASE.
You need to use an IF() construct: select if(sq.presuf=0,concat(pl.name,' ',sq.tag),concat(sq.tag,' ',pl.name)) as name, pl.email, pl.icq from squads sq, players pl where sq.name=pl.squadname; Note: you do NOT use AS when aliasing the table name... you had it correct in your first post. |
|
#4
|
|||
|
|||
|
Thanks Rod..That worked perfectly.
According to the MySQL manual, case statements are supported, and the manual also states that tables are aliased using 'as'. Pretty obvious case doesn't work the way it does in MS T-SQL tho...anyway, it worked, and thanks for your help! |
|
#5
|
|||
|
|||
|
Oops, you're right about using AS to alias tables, just never done it that way or seen it done that way.
You are also correct about CASE, however, are you using the correct manual for the version of MySQL you are running. CASE wasn't added until 3.23.3 |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > CASE statements in MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|