Re: CASE Statement

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: Tue, 24 Jun 2008 10:45:37 -0700 (PDT)
Message-ID: <e15cd303-2448-4d53-9489-6e6e1d3e3254@c65g2000hsa.googlegroups.com>


On Jun 24, 10:30 am, Vince <vinn..._at_yahoo.com> wrote:
> 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

Besides what Vince pointed out the case statment can appear in the SELECT clause and in the WHERE clause and since a select can appear in the FROM clause you can probably find a way to filter the data to get what you want.

Also remember that you can next CASE statements.

HTH -- Mark D Powell -- Received on Tue Jun 24 2008 - 12:45:37 CDT

Original text of this message