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


Date Dimension


Date Dimension

Author
Message
srjayanthi
srjayanthi
SSC Journeyman
SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)

Group: General Forum Members
Points: 77 Visits: 168
Comments posted to this topic are about the item Date Dimension
ERBIRD
ERBIRD
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 22
I like a cte better.. something like

WITH mycte
AS (
SELECT
CAST('2000-01-1' AS DATETIME) DateValue
UNION ALL
SELECT
DateValue + 1
FROM
mycte
WHERE
DateValue + 1 < '2049-12-31'
)
INSERT INTO
[dbo].[DimDate]
(
[Date]
, [DayNumberOfYear]
, [DayNameOfWeek]
, [DayOfWeek]
, [DayOfMonth]
, [WeekNumberOfYear]
, [MonthNumberOfYear]
, [MonthName]
, [CalendarQuarter]
, [CalendarYear]
, [QuarterName]
)
SELECT
DateValue AS [DATE]
, DATEPART(dy, DateValue) [day of year]
, DATENAME(dw, DateValue) [Day]
, DATEPART(dw, DateValue - 1) [day of week]
, DATEPART(dd, DateValue) [day of month]
, DATEPART(ww, DateValue) [week]
, DATEPART(mm, DateValue) [month]
, DATENAME(mm, DateValue) [month]
, DATEPART(qq, DateValue) [quarter]
, DATEPART(yy, DateValue) [year]
, 'Q' + CAST(DATEPART(qq, DateValue) AS CHAR(1)) [quarterName]
FROM
mycte
OPTION
( MAXRECURSION 0 )

will generate the table in one statement and seems to be fairly fast
GPO
GPO
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1696 Visits: 1935
You're both committing unnecessary RBAR.

:-)

One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important.
Bertrand Russell

RonKyle
RonKyle
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6828 Visits: 3620
For one time populations, there shouldn't be an issue with RBAR.



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