Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

case string not working

Status
Not open for further replies.

RikForgo

Programmer
Jul 31, 2002
59
US
Hello all ... be gentle, I'm new at this:

I've got a simple case query. One works (the top one), but when I try to add additional columns to the query it fails. I reckon it's a pretty simple mistake I'm making, but I don't know what. Any help is appreciated.

-----------------------------------------------------
This works ...

SELECT CASE WHEN CHARACTER_LENGTH(system) > 65 then
CONCAT(LEFT(system, 60), " ...")
ELSE
system END

------------------------------------------------------

This doesn't ...

SELECT CASE WHEN CHARACTER_LENGTH(system) > 65 then
CONCAT(LEFT(system, 60), " ..."), wsh_year, id
ELSE
system, wsh_year, id END
FROM wsh

Maybe an IF statement would work better here?
 
SELECT CASE WHEN CHARACTER_LENGTH(system) > 65 then
CONCAT(LEFT(system, 60), ' ...')
ELSE
system end , wsh_year, id
FROM wsh
 
Thanks, that works fine. If I wanted to create an alias for the column, how would I do that? The first select statement (before the Else) is the current column name.

When I add 'AS system' to the the end of the first string, it fails.

Ex.

SELECT CASE WHEN CHARACTER_LENGTH(system) > 60 then
CONCAT(LEFT(system, 60), ' ...') AS system
 
Put it after end. case ... end counts as one expression

CASE WHEN CHARACTER_LENGTH(system) > 65 then
CONCAT(LEFT(system, 60), ' ...')
ELSE
system end as system
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top