If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Last row in an history table

Started by Rosanero4Ever, 13 Sep 2012 04:21:28 AM

Previous topic - Next topic

Rosanero4Ever

Hi all,

I'm a newbie in the Cognos world.
I have an history table where for each person exist some rows, for example:







NameLastNameJobStart_dateFinish_date
RobertDe NiroActor01/01/201001/01/2011
RobertDe NiroRegist01/01/201101/01/2012
RobertoBaggioFootball player01/01/198901/01/2001
RobertoBaggioCoach01/01/200401/01/2012

Now i would create a query subject to find the last job of Robert De Niro and Roberto Baggio.

Does anybody can help me to solve this problem? Thanks in advance

CognosPaul

This is less of a Cognos question and more of a general design question.

The type of table you've described is a SCD Type 2. That type is very good at finding the state of a certain element on a specific date (today for example) or against a range of dates, but it's entirely unsuited for finding the last state of the element. In terms of the query, you would need complex logic (probably in the terms of a self join) to get it.

The correct way of dealing with this is to modify the table to add a last and current state flags. This would allow you to do a simple select * from history where last = 1. The change should be done in the ETL level.

If that's not possible, then you'll need to do something like this.
Create a new data source query called EmpLastDate with: select id, max(finish_date) last_date from history group by id It might be better to make that a view in the database to give the db optimizer a better chance to work with it.
Join that table on the history table on history.id = emplastdate.id and history.finish_date=emplastdate.last_date
In the business layer create a filter that has [EmpLastDate].[id] = [EmpLastDate].[id].
When you drag that filter into the report, it will force the join to the EmpLastDate table, thus filtering the data that you need.

Rosanero4Ever

Hi,
above all thanks for your reply.
I can't use an ETL practice because I need to execute a query in real time on main data source.
Have you any other idea?
Thanks again

CognosPaul

How is the main data source populated? It should be a trivial matter to modify the process to add flag fields.

If the record is being closed the update could be:
update history set finish_date = ? and last_flag = 1 and current_flag = 0 where record_id = ?

If a new record is being inserted, you just need to do a
update history set last_flag = 0 where emp_id=?;
and add last_flag =1 and current_flag = 1 to the insert statement.

Again, it is possible without modifying the source system, with the SQL I posted above. But that will be significantly slower than the correct way of doing it.