SSRS DB2当参数为null / empty时,返回所有值

时间:2017-02-09 17:31:46

标签: sql reporting-services db2

我有一些报告参数没有任何默认值。在启动报告时,我希望它显示所有结果,并为用户提供一个选项,通过输入参数来过滤掉记录。

以下是我正在尝试的查询,如果我为参数硬编码某些字符串,但是当我将查询放入带有问号的报告时失败,那么这是有效的:

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 '%' || ? || '%'

每个参数都是文本格式,如果像这样执行where子句,查询将在报告中“起作用”:

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

但是所有结果都不会在启动时显示,因为空字符串。

任何建议表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

有一个标准技巧可以用于null变为通配符,这是函数coalesce - 就像这样:

   product like coalesce(?, product)

如果有一个值,则评估为

   product like value

如果存在null,则评估为

   product like product

总是如此。

相关问题