cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Where condition in SQL

Former Member
0 Kudos

Please suggest best ways to write dynamice SQL condition as my requirement deals with 9 input parameters and there will be scenarios where values won't be passed for around 7 input parameters.

One option is by using IF ELSE statement and write separate SELECT statements accordingly which will increase the code lines as 7 parameters are considered. I saw blogs where EXECUTE IMMEDIATE is not suggested to use.


Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182114
Active Contributor
0 Kudos

Hi Karthik,

Give a try playing with parameters and OR:

select

...

from

...

where (BUKRS = :p_bukrs OR :p_bukrs = '')

and (GJAHR = p_gjahr or :p_gjahr = '')

.....

In one case I tested I saw a performance degradation with these OR's but still acceptable.

You need to run into your scenarios to decide which is best for your case.

Regards, Fernando Da Rós