If you have an application where you need to track the changing values of information over time and want to be able to see what a snapshot of the information looked like at any point in time, you can use the following method in SAP IQ:
- All tables have an effective_date and end_date column added
- Data in an existing row is never updated!
- When data needs to be updated or changed, you insert a new row with the changed data and a new effective_date and an end_date of '9999-12-31'
- All pre-existing data is then flagged with an end_date. Having both an effective_date and end_date marks the row as being a previous version or previous value for a row
- An end_date of 9999-12-31 marks the row as the newest piece of data
The methodology above allows you to write queries and reports that look at data where the "as of" date is between effective_date and end_date.
For example, if you had the following data:
Key | Value | effective_date | end_date |
---|---|---|---|
key1 | xx | 2010-01-01 | 2010-01-01 |
key1 | xx | 2010-01-01 | 9999-12-31 |
So, when searching for the Key + Value pair, you would run this type of query:
Select * from my_table where '2009-01-01' between effective_date and end_date
This would return the first row of data since 2009-01-01 sits between the effective_date and end_date for that row