Case in Select Statement
Posted in 2006
Hi,
I have SQL:
In original application we have simple SQL:
SELECT field1, field2, field3, field4, field5
from table
where field1=22 AND field2 IS NULL
ORDER BY field2
Unfortunately, I have to change returned value of field5 in this query.
I put CASE statement to do this, and got SQL:
SELECT field1, field2, field3, field4,
case
when char_length(field5) > 3 then substr(field5,0,2)
else field5
end case
FROM table1
WHERE
field1=22
AND field2 IS NULL
ORDER BY field2
In dbaccess this query works fine, but in application I've got error,
that in this query field5 is not declared.
I try to use "as name" statement after "case", but dbaccess return
syntax error.
Question is how to name "case" statement id this query as "field5" ?
Best regards
--
Janek