Home » SQL & PL/SQL » SQL & PL/SQL » Optional Field in form
Optional Field in form [message #269153] Thu, 20 September 2007 21:08 Go to next message
someone_somebody
Messages: 5
Registered: September 2007
Junior Member
Hi,

I have a form with 4 mandatory fields and 3 optional fields to call a report. How do I construct my SQL for the optional fields? Do I use OR in my SQL WHERE clause?

I would greatly appreciate your help. Thank you!

*Using 10g
Re: Optional Field in form [message #269163 is a reply to message #269153] Thu, 20 September 2007 22:26 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Are you looking for something like this?
select *
  from emp
 where ename = :p_name -- mandtory
   and deptno = nvl(:p_deptno,deptno); -- optional
You can also use OR
and (deptno is null or deptno = :p_deptno)
Here you need to pass p_name, but you may or may not pass the p_deptno. If you pass p_deptno, it will filter out on that otherwise it is same as there is no filter on deptno.

By
Vamsi

[Updated on: Thu, 20 September 2007 22:28]

Report message to a moderator

Re: Optional Field in form [message #269166 is a reply to message #269163] Thu, 20 September 2007 22:41 Go to previous message
someone_somebody
Messages: 5
Registered: September 2007
Junior Member
Hi Vamsi,

Thank you very much! It's exactly what I would like to do.

-Samantha
Previous Topic: SQL
Next Topic: Select into statements for several declared variables
Goto Forum:
  


Current Time: Sat Dec 03 05:45:31 CST 2016

Total time taken to generate the page: 0.22588 seconds