SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create and Populate a Date Dimension Table


Create and Populate a Date Dimension Table

Author
Message
Joey Morgan
Joey Morgan
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 34
Comments posted to this topic are about the item Create and Populate a Date Dimension Table
dcraday
dcraday
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 191
Nice - But you have missed President's day as a Holiday. Third Monday of February.
Joey Morgan
Joey Morgan
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 34
Thank you for pointing that out. I based the holidays on a list from the company where I worked at the time, and they didn't take that one off. It would be easy enough to add the code for that.
After MLK Day, insert:
--President's Day (3rd Monday)
([Month] = 2
AND [DAY_OF_WEEK] = 2
AND DATE_ID IN (SELECT
MIN(DATE_ID) + 14
FROM
DATE_DIM
WHERE
[Month] = 2
AND [DAY_OF_WEEK] = 2
GROUP BY
[Year])
)

fahey.jonathan
fahey.jonathan
Mr or Mrs. 500
Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)Mr or Mrs. 500 (576 reputation)

Group: General Forum Members
Points: 576 Visits: 400
Thank you for the informative script.

I noticed that many of the fields are defined as SMALLINT, even those that would never go over a TINYINT value. These include DAY_OF_WEEK (max 7), MONTH (max 12), and QUARTER (max 4). Is there a reason you chose SMALLINT over TINYINT in these cases?

Also, the SQL_DATE column is defined as a DATETIME (8 bytes) rather than a DATE (3 bytes), even though it appears that only whole dates will be used.

Changing the values to the smallest datatype necessary to hold the values changes the row width from 263 bytes to 93 bytes (by my calculations). I expect that would result in better performance because of decreased page reads. How would using the larger datatypes be a benefit?
Joey Morgan
Joey Morgan
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 34
I originally learned the technique against SQL Server 2000, and never thought to improve it. Thanks for the suggestion! It's not bad for 25 years or so, but I can see it getting to be a worthwhile benefit if someone wanted to run a century and add other reporting fields.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search