There are many ways by which people populate such facts. Here is what did today in one of my projects:
I am using Kimball's spread sheet to populate the date dimension. So, surrogate keys are kind of 'smart' (I know , I know you don't want surrogate keys to be smart ...)
For example key for '12/5/2009' will be '20091205'.
Assuming this is the scheme you are using for date dimension surrogate keys, you can use the following script to load the fact table
ORDER_DATE_KEY = RTRIM(LTRIM(STR(DATEPART(yyyy,@myDate)) +
RTRIM(CASE WHEN Month(@myDate) <>
THEN '0' + CONVERT(Char,DATEPART(Month,@myDate))
ELSE CONVERT(Char,DATEPART(Month,@myDate)) END) +
RTRIM(CASE WHEN Day(@myDate) <>
THEN '0' + CONVERT(Char,DATEPART(dd,@myDate))
ELSE CONVERT(Char,DATEPART(dd,@myDate)) END) )),
SHIP_DATE_KEY = RTRIM(LTRIM(STR(DATEPART(yyyy,@myDate2)) +
RTRIM(CASE WHEN Month(@myDate2) <>
THEN '0' + CONVERT(Char,DATEPART(Month,@myDate2))
ELSE CONVERT(Char,DATEPART(Month,@myDate2)) END) +
RTRIM(CASE WHEN Day(@myDate2) <>
THEN '0' + CONVERT(Char,DATEPART(dd,@myDate2))
ELSE CONVERT(Char,DATEPART(dd,@myDate2)) END) ))
No comments:
Post a Comment