简体   繁体   English

在多个级别上运行报表时,如何在Cognos报表中重用查询和页面

[英]How to reuse query and page in Cognos report when running reports on multiple levels

I have Query A and Query B, and both have data items level 1, level 2 and level 3. 我有查询A和查询B,并且都具有级别1,级别2和级别3的数据项。

And I have three joined queries using query A and query B as below. 我有三个使用查询A和查询B的联合查询,如下所示。

Joined Query 1 ---- a.level 1 = b.level 1

Joined Query 2 ---- a.level 1 = b.level 1 and a.level 2 = b.level 2

Joined Query 3 ---- a.level 1 = b.level 1 and a.level 2 = b.level 2 and a.level 3 = b.level 3

When the user select level 1 on the prompt page, the report then use Joined Query 1 to retrieve data. 当用户在提示页面上选择级别1时,报告将使用Joined Query 1来检索数据。

When the user select level 2 on the prompt page, the report then use Joined Query 2 to retrieve data. 当用户在提示页面上选择级别2时,报告将使用Joined Query 2来检索数据。

When the user select level 3 on the prompt page, the report then use Joined Query 3 to retrieve data. 当用户在提示页面上选择级别3时,报告将使用Joined Query 3来检索数据。

However, in this way I have to create 3 pages and 3 lists and use different Joined Queries. 但是,以这种方式,我必须创建3个页面和3个列表,并使用不同的Joined Queries。 The maintenance effort is too high when a requirement change occurs cause I have to modify triple times. 当需求发生变化时,维护工作量太高,因为我必须修改三遍。

Is there any idea to reuse query and page in this situation? 有什么想法在这种情况下重用查询和页面吗? I am wondering if there is conditional join functionality in the Cognos Report Studio? 我想知道Cognos Report Studio中是否有条件联接功能?

I have a novel solution to your problem. 对于您的问题,我有一个新颖的解决方案。 Instead of creating three pages you can get away with one by manipulating your join columns. 除了创建三页之外,您还可以通过处理联接列来摆脱一页。

Let's simplify your example to two cases determined by radio button: 让我们将示例简化为由单选按钮确定的两种情况:

  1. You want to join on one column ([Level1]) 您想加入一列([Level1])
  2. You want to join on two columns ([Level1] & [Level2]) 您想加入两列([Level1]和[Level2])

For the column you always want to join on, we don't change anything. 对于您一直想加入的列,我们不会做任何更改。 For the second join column we create a new data item to be used just for the join. 对于第二个联接列,我们创建一个仅用于联接的新数据项。 For this example, we'll call it 'Join2'. 在此示例中,我们将其称为“ Join2”。 For the expression we put in a CASE statement (or if..then if you prefer): 对于表达式,我们输入了CASE语句(如果愿意,则输入if..then):

CASE ?radioButton? 
WHEN 1 THEN '1' 
WHEN 2 THEN [Level2]
END

Create the same data item in both queries to be joined. 在两个要连接的查询中创建相同的数据项。 Obviously, the names should be adjusted to match your columns. 显然,应调整名称以匹配您的列。 Also, I assumed the level was a string, thus the '1' above. 另外,我假设级别是一个字符串,因此为上面的“ 1”。 It should match the type of the optional join column or you will get a type mismatch error. 它应该与可选联接列的类型匹配,否则您将收到类型不匹配错误。 Change the join expression to join on this second column in addition to the [Level1] column you always want to join on. 将连接表达式更改为除了您总是要连接的[Level1]列之外的第二列。

Let's examine the effect. 让我们检查一下效果。


If the user selects 1, the join condition will be: 如果用户选择1,则加入条件为:

a.[Level1] = b.[Level1] AND a.[Join2] = b.[Join2] a。[Level1] = b。[Level1]和a。[Join2] = b。[Join2]

...but the effective join will be: ...但有效的加入将是:

a.[Level1] = b.[Level1] AND a.'1' = b.'1' a。[Level1] = b。[Level1]和a.'1'= b.'1'

We've rendered the second join condition superfluous, exactly what we want. 我们已经使第二个联接条件变得多余,这正是我们想要的。


If the user selects 2, the join condition will be: 如果用户选择2,则加入条件为:

a.[Level1] = b.[Level1] AND a.[Join2] = b.[Join2] a。[Level1] = b。[Level1]和a。[Join2] = b。[Join2]

...but the effective join will be: ...但有效的加入将是:

a.[Level1] = b.[Level1] AND a.[Level2] = b.[Level2] a。[Level1] = b。[Level1]和a。[Level2] = b。[Level2]

In this case, we enforce the second-level join condition. 在这种情况下,我们强制执行第二级联接条件。


This technique assumes an inner join is used. 该技术假定使用内部联接。 Additional join conditions can be added in a similar way. 可以以类似方式添加其他加入条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM