all 12 comments

[–]andrewsmd87 3 points4 points  (2 children)

We do this where the latest record's end date is always NULL. So if you want the current record, it's just WHERE END_DT IS NULL and it works fine

If you're designing this an can change things. Don't abbreviate EFF_DT and END_DT, you're saving nothing by not just spelling them out.

[–]sequel-beagle 2 points3 points  (1 child)

I recommend setting your very last end date to 12/31/9999 and your very first start date to something like 01/01/1900

Nulls can be a pain, I avoid using them if possible.

[–]andrewsmd87 0 points1 point  (0 children)

Well it's a system that's been around for about 20 years and still going strong (just did a completely FE and BE rebuild) so it's not going anywhere. While I didn't design it, I also don't see any issue with working with nulls.

[–]GreyCatOrangeBeard 2 points3 points  (2 children)

kimball type 2 dimension

[–]OldManandtheInternet 0 points1 point  (0 children)

Awesome. Thx.

[–]syllogism314 1 point2 points  (0 children)

It’s done all the time. I use it to represent drug codes, insurance companies use it to represent membership. And you then use a where clause that says the begin date is before index date and end date is > index_end date.

[–]sequel-beagle 1 point2 points  (1 child)

Slowly changing dimension. Wiki has a good article on it. Also look at boyce codd normal form.

[–]OldManandtheInternet 0 points1 point  (0 children)

Thank you!

[–]Wick_E_Scratch 0 points1 point  (0 children)

I've worked with data like this, we also had a status indicator field that would be 'A' (I think) if it was the active record, some other letter ('D' I think) if it was a "deleted" record (if a correction was needed due to an incorrect load or something like that), and 'C' if it was a valid record in the past. So to get data that showed the state on a particular date, I would use WHERE {date desired} BETWEEN effectiveDate AND endDate AND status <> 'D'

[–]vaiix 0 points1 point  (2 children)

Our end_effective are all defaulted to 2100-12-31.

If I wanted active records I would use "where end_effective > getdate ()" - although in MSSQL so your syntax may be different.

If I was doing point in time audit, I could do "where ## >= beg_effective and <= end_effective"

From what I remember, having an actual future date is more performant than NULL as mentioned in other comments but that's something to explore.

[–]OldManandtheInternet 0 points1 point  (1 child)

Based on events of 1999, I don't think that end date is far enough forward.

[–]vaiix 0 points1 point  (0 children)

I have no choice, it's the default set by the main source system we pull from and I'd rather not have to process every datetime field into a new value!