【问题标题】:Pass string parameter to SQL over jdbc query in pentaho CDE在 pentaho CDE 中通过 jdbc 查询将字符串参数传递给 SQL
【发布时间】:2019-07-31 23:06:44
【问题描述】:

我正在尝试将另一个查询获得的字符串参数传递给同一仪表板中的另一个查询,但是当我使用该参数时,没有选择任何结果。什么是正确的语法或问题出在哪里。

我是 pentaho biserver-CE 的初学者。我使用 6.1 版。通过 JDBC 连接到 SQL Server 2016 SP1。

现在我正在从发票制作销售仪表板,我想按时间单位(可以正常工作)和国家/地区快捷方式(不起作用)制作动态过滤器。如果我直接用引号传递某个国家/地区的快捷方式,它可以正常工作,但是当我用参数替换它时,它不会选择任何内容(也在 CDA 预览中)。当我在 Jasper 中进行一些报告时,我在参数中使用感叹号来传递引用的值,但在这里我没有为 Pentaho 找到类似的东西。

select  top 10
        invrow.item as ITEM,
    invrow.agent as AGENT,
    sum(invrow.qt) as MEASURE,
    sum(invrow.val) as VALUE
from    invrow
left join   invhead on invrow.type = invhead.type 
                and invrow.nr = invhead.nr
left join   art on invrow.item = art.item
where   left(invhead.date,4) = ${year}
and invhead.country like ${Country}
group by    invrow.item, invrow.agent, invhead.country
order by MEASURE DESC

参数 ${Country} 被同一字段的另一个查询获取。有查询获取参数:

select distinct 
        invhead.country
from
        invhead
where
        left(invhead.date,4) = ${year}

原始查询只显示当我像这样将参数 ${Country} 替换为例如“UK”时。

效果很好:

select  top 10
        invrow.item as ITEM,
    invrow.agent as AGENT,
    sum(invrow.qt) as MEASURE,
    sum(invrow.val) as VALUE
from    invrow
left join   invhead on invrow.type = invhead.type 
                and invrow.nr = invhead.nr
left join   art on invrow.item = art.item
where   left(invhead.date,4) = ${year}
and invhead.country like 'UK'
group by    invrow.item, invrow.agent, invhead.country
order by MEASURE DESC

现在,当我使用参数时,选择列表中没有任何内容,但有行,应该选择。

【问题讨论】:

  • 从国家查询返回多少个国家?
  • 国家/地区的数量取决于所选的时间范围,因为它每年/每月都不同。由于所选时间范围,此参数的可行值由另一个选择动态给出,但最常见的是在 12 到 20 个国家/地区之间。

标签: sql-server pentaho-cde


【解决方案1】:

语法是正确的,但是这种传递参数的方式只适用于单值参数。

要传递参数数组,正如您似乎正在尝试的那样,您需要将参数作为in 运算符的右侧传递,

(...)
and invhead.country in ( ${Country} )
(...)

并将参数设置为StringArray类型。

【讨论】:

  • 感谢@nsousa,但是这种传递参数的方式对于单值参数和多值参数都没有结果。我必须找到一种方法,如何将参数中的值粘贴到单引号中,这样才能正常工作。
  • 检查您的日志。发送到 jdbc 的 SQL 可能有错误。
猜你喜欢
  • 1970-01-01
  • 2013-12-21
  • 1970-01-01
  • 2015-04-25
  • 1970-01-01
  • 2012-10-23
  • 1970-01-01
  • 2019-02-24
  • 1970-01-01
相关资源
最近更新 更多