0

I have some report parameters that are not defaulted to anything. On start up of the report I would like it to show all results and give the user an option to filter out records by then entering parameters.

Here is the query I am trying which works if I hard-code some strings for the parameters but fails when I put the query into the report with the question marks:

with data as(
select product, productnumber, employee, dateran, timeran, 
       filename, standarddeviation, highdata, lowdata
from   schema.table x 
)
select * 
from data
where product like '%' || ? || '%' 
and employee like '%' || ? || '%' 
and productnumber like '%' || ? || '%'

Each of the parameters are text format and the query will 'work' in the report if do the where clause like this:

where product like ?
and employee like ?
and productnumber like ?

But all of the results then will not show on start up because the empty strings.

Any advise is appreciated. Thank you!

1 Answer 1

2

There is a standard trick to use for null becoming wildcard which is the function coalesce -- like this:

   product like coalesce(?, product)

if there is a value this evaluates as

   product like value

if there is a null this evaluates as

   product like product

which is always true.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.