how to get the latest record from dimension table?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
karthikgk0705
Premium Member
Premium Member
Posts: 45
Joined: Tue Aug 29, 2006 2:59 am
Location: Bangalore

how to get the latest record from dimension table?

Post by karthikgk0705 »

Hi all,
I have a scenario which goes like this.
i have a dimension table named 'customer' with columns customer id,customer name and address.
If a particular customer say A,keeps changing his address,how do i bring in those changes in my customer table.
Conditions are that all the previous addresses should also be preserved,eff date or time stamp shd not be used.And also when the end-user enquires about the customer A,he shd get the latest details about him.

Can anyone clarify me?
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Hi Karthik

Please do a search on Slowly Changing Dimension Type 2 you will get heaps of results to answer your question
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create a query that constrains on the customer ID and the most recent (probably maximum) surrogate key value via a correlated subquery.

Code: Select all

SELECT T1.CUSTOMER_KEY 
FROM   CUSTOMER_DIM T1
WHERE  CUSTOMER_ID = 'A'
AND    T1.CUSTOMER_KEY = (SELECT MAX(T2.CUSTOMER_KEY)
                          FROM   CUSTOMER_DIM T2
                          WHERE  T1.CUSTOMER_ID = T2.CUSTOMER_ID);
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

If timestamp or data shouldnt be used, then to fetch the latest information, you need to have another column which represents the version of the data. Or as simply utilizing the surrogate key as Ray suggested, which will increase sequentially.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Post Reply