Is there a way to set a where clause with variable to be optional?
with a sql query like:
select * from my_table
where id = {v_var}
I would like to ignore completely the where clause if my input was null.
if my input is 123, my sql clause would be:
select * from my_table
where id = 123
and if my input is null, my sql clause would be:
select * from my_table
Is there a way to make something like this?
Optional WHERE clause in Reports
-
- Posts: 1
- Joined: Tue Apr 16, 2024 8:11 pm
-
- Posts: 6364
- Joined: Tue Mar 20, 2018 5:34 am
Re: Optional WHERE clause in Reports
Hello,
Please try to check:
select * from my_table
{v_var == 0 ? "" : "where id = " + v_var}
Thank you.
Please try to check:
select * from my_table
{v_var == 0 ? "" : "where id = " + v_var}
Thank you.