Re: CASE Statement

From: Vince <vinnyop_at_yahoo.com>
Date: Tue, 24 Jun 2008 07:30:51 -0700 (PDT)
Message-ID: <1e7661f5-1bd4-4501-93fd-d8e6c59732aa@34g2000hsf.googlegroups.com>


On Jun 24, 7:14 am, Mtek <m..._at_mtekusa.com> wrote:
> Hi,
>
> I know I can probably do this in an IF statement(s).  But, I was
> wondering if you can have a query with a CASE in it, and later in the
> query refer to a value eariler in the query.
>
> My guess is no, but if I case column 1, and column 2 is based on the
> value derived from the case of column 1, and so on, is that easily
> done?
>
> If not, it is onto putting it in the code......
>
> Thanks!
>
> John

John,
You can try using an inline view containing column 1, using its value in the outer query to formulate column 2. Something like this:

select case col1 when....end as column_2,

          column_1, ...
from ( select case table.column when ... end as column_1

         from ...
       )

Vince Received on Tue Jun 24 2008 - 09:30:51 CDT

Original text of this message