Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Creating a smart date key in the data flow?

Creating a smart date key in the data flow?

Creating a smart date key in the data flow?

I have a fact table that I currently write about 1M records to as part of a nightly table load.  I am using SSIS to pull the records over to my BI database as a staging table, which takes about 1 minute.  I then run a stored procedure that copies the rows from the staging table into my final fact table.  The primary purpose of the stored proc is to convert the five date fields (smalldatetime) in the staging table into a smart date key (int - yyyymmdd).  The stored proc adds another 30 - 40 minutes to the process.

My question - would it be faster to create the date key as part of the SSIS Data Flow task, and, if so, what transform would I use?  I've tried doing it in a Derived Column transform, but I can't get the month and day leading zeros to work.  I've got to believe that someone has solved this issue before, but I can't find any references to it.

The select statement in the stored proc that I use for the transform is:


        + dbo.PadString_fn(convert(varchar(2),Month(stage.ApptDate)),'0',2,0)
        + dbo.PadString_fn(convert(varchar(2),Day(stage.ApptDate)),'0',2,0)

where dbo.PadString_fn is a user-defined function that adds the leading '0' to months and days that are only one digit.


RE: Creating a smart date key in the data flow?

Never mind!  After playing with a bunch of increasingly complex (and ineffective) transforms, I realized I could just use the Lookup Transform against my DimTime dimension table.  It added about 2 seconds of overhead to my SSIS package.

RE: Creating a smart date key in the data flow?

THe lookup transform is one way if your key is in that format  you could also use a derived collumn that uses DatePart() and conctinates the Year Month and Day Dateparts into a single stream.  

Personally my datekeys are a Floor(Cast(DateCol as float))
which I can do as part of the Extract.

Shoot Me! Shoot Me NOW!!!
                           - Daffy Duck

RE: Creating a smart date key in the data flow?

Just thought I'd pass this along - I ran into a better way to create my smart date key in SQL.  Now I can do it as part of the extract rather than using a lookup:


cast(convert(char(8),stage.ApptDate,112) as int)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close