Re: Case in Select Statement
Posted in 2006
Because
case
when
end case
You defined the column as case. So in your application you will have to
refer to the column as case or positionally.
case
when
end
is all you really need.
JPS wrote:
> 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