I have a stored procedure where i have the following query:
SELECT COUNT(*)
into cust_count
FROM cust_acct_item
WHERE (sobp_me = substr(sobp_in,1,4) or sobp_me like ltrim(rtrim(substr(sobp_in,1,4))) or sobp_me is null)
AND (sobp_le = substr(sobp_in,5,3) or sobp_le like ltrim(rtrim(substr(sobp_in,5,3))) or sobp_le is null)
AND (sobp_ae = substr(sobp_in,8,3) or sobp_ae like ltrim(rtrim(substr(sobp_in,8,3))) or sobp_ae is null)
AND (cr_facct= facct_in or cr_facct like ltrim(rtrim(facct_in)) or cr_facct is null)
AND (cr_orgc = orgc_in or cr_orgc like ltrim(rtrim(orgc_in)) or cr_orgc is null);
Where sobp_in,facct_in,orgc_in are the input parameters to the stored procedure.
Now I have to modify this query in such a way that
IF any of these input parameters have the value, then I have to use the value . e.g
if orgc_in has the value, then use the condition cr_orgc = orgc_in .
ELSE use null or any values for comparison.
e.g. cr_orgc like orgc_in or cr_orgc is null.
How can I modify the query above to do this.
Please help .Thanks a ton.
SELECT COUNT(*)
into cust_count
FROM cust_acct_item
WHERE (sobp_me = substr(sobp_in,1,4) or sobp_me like ltrim(rtrim(substr(sobp_in,1,4))) or sobp_me is null)
AND (sobp_le = substr(sobp_in,5,3) or sobp_le like ltrim(rtrim(substr(sobp_in,5,3))) or sobp_le is null)
AND (sobp_ae = substr(sobp_in,8,3) or sobp_ae like ltrim(rtrim(substr(sobp_in,8,3))) or sobp_ae is null)
AND (cr_facct= facct_in or cr_facct like ltrim(rtrim(facct_in)) or cr_facct is null)
AND (cr_orgc = orgc_in or cr_orgc like ltrim(rtrim(orgc_in)) or cr_orgc is null);
Where sobp_in,facct_in,orgc_in are the input parameters to the stored procedure.
Now I have to modify this query in such a way that
IF any of these input parameters have the value, then I have to use the value . e.g
if orgc_in has the value, then use the condition cr_orgc = orgc_in .
ELSE use null or any values for comparison.
e.g. cr_orgc like orgc_in or cr_orgc is null.
How can I modify the query above to do this.
Please help .Thanks a ton.