If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Informix Function - Dynamic where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-10, 22:48
msreddy13 msreddy13 is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Informix Function - Dynamic where clause

Hi,

How to implement dynamic where clause in Informix Function?
Here is my code:

Create Function testFun(pv_dept integer)

RETURNING varchar(20), varchar(70);

Define lv_Name varchar(20);
Define lv_Details varchar(70);

FOREACH
Select name, details into lv_Name, lv_Details
from EMP where job='Manager'
-- have to add the following condition based on parameter
-- if parameter is null then display all
-- else display only that dept
and depet_no = pv_dept


return lv_Name, lv_Details WITH RESUME;

End FOREACH;

END FUNCTION;

Thank you
Reply With Quote
  #2 (permalink)  
Old 10-28-10, 08:53
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 545
Hi,
there is no need for dynamic where clause, the conditions you posted with application of appropriate logical operation will satisfy the requirement:
Code:
WHERE job='Manager'
   AND (pv_dept is null OR depet_no = pv_dept)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On