Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: dynamically determining the field to select
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