简体   繁体   中英

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.

And I have three joined queries using query A and query B as below.

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.

When the user select level 2 on the prompt page, the report then use Joined Query 2 to retrieve data.

When the user select level 3 on the prompt page, the report then use Joined Query 3 to retrieve data.

However, in this way I have to create 3 pages and 3 lists and use different 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?

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])
  2. You want to join on two columns ([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'. For the expression we put in a CASE statement (or if..then if you prefer):

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. 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.

Let's examine the effect.


If the user selects 1, the join condition will be:

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

...but the effective join will be:

a.[Level1] = b.[Level1] AND 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:

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

...but the effective join will be:

a.[Level1] = b.[Level1] AND 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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