Setting up an "All" Parameter

Setting up an "All" Parameter

 

This short tutorial is fairly similar to the last one, let's say it's an improved version:

We work again with Pentaho Report Designer 3.5. Imagine you want to give your users the possibility to choose either one of the parameter values or all. So how can we implement this with a MySQL query? 

 

The approach is as follows:

 

Set up the query to for the parameter values like this:

 

SELECT

"All Countries" AS country_name

UNION

SELECT

country_name

FROM

table

;

 

We do the same for the channels query. Please keep in mind that UNION will remove any duplicates. If you are sure that you have no duplicates, you can use UNION ALL to improve the performance.

 

Set up a new parameter called "country_name", tick "mandatory", choose the above query as the source, set the type to string.

 

Now change the main query that feeds the report like this:

 

SELECT

[...]

WHERE

(cc.channel_name = ${channel_name} OR "All Channels" = ${channel_name}) AND

(country_name = ${country_name} OR "All Countries" = ${country_name}) AND

the_date >= ${start_date} AND

the_date <= ${end_date}

GROUP BY 1,2,3,4

;

 

Save everything and run the report ... you should see the all options now in your pull down menu:

As some of you might use Oracle as well, a user named "zulu" from the pentaho forum pointed out that:

"Not sure if this helps you now, but depending on your SQL dialect, a

NULL (meaning nothing) is treated differently to a "NULL" string.

 

In Oracle your predicate could be: 

WHERE (${media} IS NULL OR media=${media}). 

Oracle applies "lazy" logic, so if your Media parameter is not

completed by the user (meaning it "IS NULL"), the condition will not

even check the "media=${media}" part."

 

Just a remark from my side: My original post included a query like this one "(media = ${media} OR 'All Media' = ${media})"

You can find the original post here.

 

Update 2012-05-30: Somebody asked me how to achieve the same with mulitselect parameters. Here is the approach that works for me (It's a different dataset, but you get the idea):

 

SELECT

     `city_sales`.`date`,

     `city_sales`.`continent`,

     `city_sales`.`country`,

     `city_sales`.`city`,

     `city_sales`.`revenue`

FROM

     `city_sales`

WHERE

(city IN (${CITY}) OR "All cities" IN (${CITY}))

 

Note: I defined the CITY parameter as type STRING.

 

转自:http://diethardsteiner.blogspot.jp/2009/10/setting-up-parameter.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值