Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: dynamically determining the field to select

Re: dynamically determining the field to select

From: Peter Sylvester <peters_no_spam_please_at_mitre.org>
Date: Wed, 21 Jul 2004 13:20:34 -0400
Message-ID: <cdm8l3$901$1@newslocal.mitre.org>


Check out the "case" statement, I believe it can do this. May also be able to use the "decode" function.

--Peter

hastenthunder wrote:
> Hi SQL Masters,
>
> I'm trying to perform a rather simple query, but the field I'm selecting
> from the table can only be determined at run time, basing on the value of
> some other field in the same table. The logic is like:
>
>
> IF (year_of_sales < 1995) THEN
> SELECT fieldA
> FROM myTable;
> ELSE IF (year_of_sales >1995 and year_of_sales< 1998) THEN
> SELECT fieldB
> FROM myTable;
> ELSE
> SELECT fieldC
> FROM myTable;
> END IF;
>
>
> The table looks like:
>
> Create tabe myTable (year_of_sales number(4),
> fieldA varchar2(5),
> fieldB varcahr2(5),
> fieldC varchar2(5));
>
>
> Can someone help me to put the above query into a single SQL statement? Is
> it possible?
>
> Thanks a lot.
>
>
Received on Wed Jul 21 2004 - 12:20:34 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US