Optional WHERE clause in Reports

Stimulsoft Reports.WEB discussion
Post Reply
pedroalves5770
Posts: 1
Joined: Tue Apr 16, 2024 8:11 pm

Optional WHERE clause in Reports

Post 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?
Lech Kulikowski
Posts: 6291
Joined: Tue Mar 20, 2018 5:34 am

Re: Optional WHERE clause in Reports

Post by Lech Kulikowski »

Hello,

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

Thank you.
Post Reply