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

Home -> Community -> Usenet -> comp.databases.theory -> SQL query

SQL query

From: PRatcliff <philippa.ratcliff_at_acgov.org>
Date: 18 Feb 2004 15:56:24 -0800
Message-ID: <ea69d2d8.0402181556.261c51c2@posting.google.com>


Hello,

I am constructing a stored procedure to run based on user input. What I WANT to do is basically this:

SELECT *
FROM tableA A
join tableB B
on A.idfield = B.idfield
WHERE CASE WHEN @userinput = 'A'

       THEN A.datefieldA BETWEEN @startdate AND @enddate
       ELSE B.datefieldB BETWEEN @startdate AND @enddate END

or this:

SELECT *
FROM tableA A
join tableB B
on A.idfield = B.idfield
WHERE if @userinput = A then A.datefieldA BETWEEN @startdate AND @enddate
else B.datefieldB BETWEEN @startdate AND @enddate

I know I can't use CASE in the above fashion, but I want to use a single query to pull data where the 'where' field can change depending upon the user's selection. How can I change the contstraint field in the WHERE clause based on a variable value?

Thanks in advance & cheers,
PRatcliff Received on Wed Feb 18 2004 - 17:56:24 CST

Original text of this message

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