Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Time Dimension best practice? Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 3:59 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, June 2, 2014 4:52 AM
Points: 4, Visits: 24
Currently I have one table and one date record with a format of (2011-05-25 23:00:00.000) I would like to create a time dimension that includes Years, Quarters and Months as it will be easier for reporting on. What is the easiest way to do this ?
Post #1433685
Posted Thursday, March 21, 2013 4:11 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 13, 2014 7:34 AM
Points: 117, Visits: 499
Create a view in SQL and base your dimension off that. You might want to write this to a table to give you some flexibility to name quarters or semesters etc

select
Year(GetDate()) As Year_Key
, Year(GetDate()) * 100 + Datepart(qq,GetDate()) As Quarter_Key
, Year(GetDate()) * 100 + Datepart(mm,GetDate()) As Month_Key
, DateName(mm,GetDate()) + ' ' + Cast(Year(GetDate()) As VarChar) As Month_Name

Mack
Post #1433691
Posted Thursday, March 21, 2013 4:12 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:00 AM
Points: 13,520, Visits: 11,313
Here's a script to create a time dimension:

Script to Populate Date Dimension, without Using a Cursor

I wouldn't stop at the month level. I would create the dimension to the date level. You never know if the requirements for reporting change and this way you'll be ready. And it aren't that many rows.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1433693
Posted Thursday, March 21, 2013 4:14 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 13, 2014 7:34 AM
Points: 117, Visits: 499
Agree - I got bored writing the SQL.....
Post #1433696
Posted Thursday, March 21, 2013 4:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, June 2, 2014 4:52 AM
Points: 4, Visits: 24
Thanks for the reply's ! I'll let you know how I get one !
Post #1433700
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse