| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> SQL query
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
![]() |
![]() |