Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a smart date key in the data flow?

Status
Not open for further replies.

FlaBusInt

IS-IT--Management
Apr 24, 2007
36
US
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:

Code:
SELECT
convert(char(4),Year(stage.ApptDate))
		+ 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.

Thanks!
 
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.
 
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.

Paul
---------------------------------------
Shoot Me! Shoot Me NOW!!!
- Daffy Duck
 
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:

Code:
SELECT
cast(convert(char(8),stage.ApptDate,112) as int)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top