Cognos 日期提示宏错误

发布于 2024-08-18 17:14:17 字数 595 浏览 3 评论 0原文

此问题适用于 Cognos Report Studio 版本 8.3 到 10.1.1。

在 Report Studio 8.3 中,我针对 MySQL 5.1 数据源运行了这个原始 SQL 查询:

SELECT enc.encounterID, enc.date
FROM enc
WHERE enc.date between #prompt('textPromptStartDate')# AND #prompt('textPromptEndDate', 'date')#

这会为用户生成文本提示。如果用户以“YYYY-MM-DD”的格式在这些提示中输入日期,例如“2010-01-15”,则查询可以正常工作。但我想用正确的日期提示替换文本提示。 替换上述提示时

#prompt('datePromptStartDate', 'date') AND #prompt('datePromptEndDate', 'date')#

当我尝试用查询运行 (不会生成错误),但我得到一个空结果集。我有一种感觉,我需要调整日期提示宏返回的日期格式,但经过几个小时的实验后,我陷入了如何调试它的困境。

This issues applies to Cognos Report Studio Versions 8.3 through 10.1.1.

In Report Studio 8.3, I've got this raw SQL query running against a MySQL 5.1 data source:

SELECT enc.encounterID, enc.date
FROM enc
WHERE enc.date between #prompt('textPromptStartDate')# AND #prompt('textPromptEndDate', 'date')#

This produces text prompts for the user. If the user enters dates into these prompts in the format of 'YYYY-MM-DD', e.g. '2010-01-15', the query works fine. But I want to replace the text prompts with proper Date prompts. When I try replacing the above prompts with

#prompt('datePromptStartDate', 'date') AND #prompt('datePromptEndDate', 'date')#

the query runs (no errors are generated), but I get an empty result set. I have a feeling I need to adjust the date format that the date prompt macro returns, but I'm stuck after many hours of experimentation as to how to debug this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南冥有猫 2024-08-25 17:14:17

对于日期,您需要将值用单引号引起来。我使用“sq”函数来执行此操作:

#sq(prompt('DateParameterFromPromptPage', 'date'))#

For dates, you need the single quotes around the value. I do this using the "sq" function:

#sq(prompt('DateParameterFromPromptPage', 'date'))#

旧时浪漫 2024-08-25 17:14:17

您可以使用日期提示控件创建提示页面,然后将它们绑定到提示宏中的参数。我在 8.4 中使用 MySQL 5.1 (ODBC) 使用上面的查询对此进行了测试,它有效。我也遇到了与您遇到的相同问题,在创建单独的提示页面并绑定控件之前没有返回任何数据。

为此,您需要采取的步骤是:

  1. 将提示页面(如果不存在)添加到报告中
  2. 提示页面
  3. 将 2 个日期提示控件添加到第一个日期提示的“参数”属性中的 ,使用: datePromptStartDate
  4. 在第二个日期提示的“Parameter”属性中,使用:datePromptEndDate

当您执行报表时,新的提示页面将替换从宏生成的提示页面,并且宏中的参数将绑定到日期控件。

编辑:
我忘了补充一点,SQL 中的宏应该如下所示:

SELECT enc.encounterID, enc.date 
FROM enc 
WHERE enc.date between #prompt('textPromptStartDate')# 
AND #prompt('textPromptEndDate')#

You can create a prompt page with date prompt controls, and then bind them to the parameters in your prompt macros. I tested this out in 8.4 with MySQL 5.1 (ODBC) using the query you have above and it worked. I also had the same problem you experienced with no data being returned prior to creating a separate prompt page and binding the controls.

The steps you would take to do this are:

  1. add a prompt page (if one doesn't exist) to your report
  2. add 2 date prompt controls to the prompt page
  3. in the "Parameter" property for the first date prompt, use: datePromptStartDate
  4. in the "Parameter" property for the second date prompt, use: datePromptEndDate

When you execute the report, the new prompt page will replace the prompt page that is generated from the macro, and the parameters in the macros will be bound to the date controls.

Edit:
I forgot to add that the macros in your SQL should look like the following:

SELECT enc.encounterID, enc.date 
FROM enc 
WHERE enc.date between #prompt('textPromptStartDate')# 
AND #prompt('textPromptEndDate')#
绳情 2024-08-25 17:14:17

可以为不使用提示页面的日期提示创建没有提示页面的提示。我在 SQL Server 上也遇到了这个问题,直到我运行了配置文件跟踪。配置文件跟踪显示 Cognos 没有在日期值周围传递引号。我通过将提示作为字符串传递、将默认验证测试字符串 (testValue) 替换为真实日期、在变量中构建字符串,然后将其传递给实际查询来解决此问题。这是我用来将日期提示转换为普通 DATE 数据类型的方法。

DECLARE @StartDate DATE = CONVERT(DATE, REPLACE(#prompt('StartDate')#, 'testValue', '1/1/2012'));

It is possible to create a prompt without a prompt page for the date prompts without using a prompt page. I ran into this exact problem as well on SQL Server until I ran a profile trace. The profile trace showed that Cognos wasn't passing quotes around the date value. I fixed the issue by passing the prompt as a string, replacing the default validation test string (testValue) with a real date, building the string in a variable, and then passing it to the actual query. Here's what I used to convert a date prompt into a normal DATE data type.

DECLARE @StartDate DATE = CONVERT(DATE, REPLACE(#prompt('StartDate')#, 'testValue', '1/1/2012'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文