Page 1 of 1

Optional WHERE clause in Reports

Posted: Tue Apr 16, 2024 8:18 pm
by pedroalves5770
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?

Re: Optional WHERE clause in Reports

Posted: Tue Apr 16, 2024 8:39 pm
by Lech Kulikowski
Hello,

Please try to check:
select * from my_table
{v_var == 0 ? "" : "where id = " + v_var}

Thank you.