Re: Case in Select Statement
Posted in 2006
Topics: SQL Development & Query Writing, Server Administration
The correct syntax is just END and not END CASE. The keyword AS is optional
before an alias, so your 5th field is being presented to your application as
column name "case"!
--
Regards,
Doug Lawry
www.douglawry.webhop.org
"JPS" <j_p_s@poczta.onet.pl> wrote in message news:ecbu0l$19t$1@news.onet.pl...
> 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
Doug Lawry napisaďż˝(a): > The correct syntax is just END and not END CASE. The keyword AS is optional > before an alias, so your 5th field is being presented to your application as > column name "case"! Thank you very much !!!! Here was the problem . Best regards -- Janek