ID Level Effective Date ExpirationDate
000012-12 2 12/01/2005 NULL
000012-12 1 12/01/2005 NULL
000012-12 2 12/01/2005 01/01/2009
000012-A12 2 10/01/1994 11/30/2005
000012-A12 2 01/01/1999 11/30/2005
000012-A12 2 09/01/2001 11/30/2005
000012-A12 1 12/01/2005 12/31/2007
Only most current Records will be fetched. It means in the above scenario Exp date - If null the record is still active. If greater then current time stamp, its future exp date , which means still active. if less then current time stamp , then terminated. Most current is the most active or latest terminated record. If it has active and terminated then only active will be shown. Else last terminated record.
One ID can have 2 rows for same effective date and exp date but multiple levels. So in that case we would need to select only 1 record for level one.
So as per the data set above below is the intended output
Output
000012-12 1 12/01/2005 NULL
000012-A12 2 12/01/2005 01/01/2009
Please help
Thomas. Please look into the following data set.
Insert #Test( Id, Level, EffectiveDate, ExpirationDate ) Values ('000872-A24',1,'1994-10-01',NULL);
Insert #Test( Id, Level, EffectiveDate, ExpirationDate ) Values ('000872-A24',1,'1999-01-01',NULL);
Insert #Test( Id, Level, EffectiveDate, ExpirationDate ) Values ('000872-A24',2,'2001-09-01',NULL );
Insert #Test( Id, Level, EffectiveDate, ExpirationDate ) Values ('000872-A24',1,'2003-01-01','2007-12-31');
when you run the query it should give 000872-A24 2 09/01/2001 NULL
but now it returns 000872-A24 1 01/01/2003 12/31/2007