Solved

sql server 2000, data for a time dimension table

Posted on 2004-04-16
4
304 Views
Last Modified: 2012-06-21
I'm using SQL Server 2000 on a XP Pro machine.  

I'm working on a DW project and need to populate a time dimension table in the data warehouse. This data is not in the OLTP and I would like to know if anyone knows of a script that will populate the columns in this table like, month, day of week, week, year. I can make the table, that is not a problem. The issue is getting the data and populating the table. Make sense?  

I would rather not have to type all this information into the table.  

Thank you for your help.
0
Comment
Question by:jandhb
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
arbert earned 50 total points
ID: 10844070
This is the script we use--should give you a good start (or something to look at):


--
--
DECLARE @Date AS DATETIME

SELECT @Date = '1900-01-01'                  --startdate

WHILE @Date <> '2040-01-05'                 --enddate
Begin
  INSERT INTO HWED_T_DATE (full_date, day_number_in_month,day_name,day_abbreviation,
                  day_of_week, weekday_weekend, week_number_in_year, week_begin_date,
                  month_number, month_name, MONTH_ABBREVIATION, quarter_number,
                  century_year, year_month, last_day_in_month, same_weekday_year_ago)
 values(
      @Date --as FullDate
      , DAY(@Date) --as DayNumberInMonth
      , DATENAME(DW, @Date) --as DayName
      , SUBSTRING(DATENAME(DW, @Date), 1, 3) --as DayAbbreviated
      , DATEPART(DW, @Date) --as DayOfWeek
      , --WeekdayWeekend =
            Case DATEPART(DW, @Date)
                  When 1 Then 'Weekend'
                  When 7 Then 'Weekend'
                  Else 'Weekday'
            End
      , DATENAME(WK, @Date) --as WeekNumberInYear
      , @Date + 1 - DATEPART(DW, @Date)-- as WeekBeginDate
      , MONTH (@Date) --as MonthNumber
      , DATENAME (MM, @Date) --as MonthName
      , SUBSTRING(DATENAME(MM, @Date), 1, 3)-- as MonthAbbreviated
      , 'Q' + DATENAME (Q, @Date)-- as Quarter
      , YEAR(@Date)--as Year
      , Year(@Date) * 100 + Month(@Date)-- as YearMo
      , --LastDayInMonthFlag =
            Case
                  WHEN MONTH(@Date + 1) <> MONTH(@Date) THEN 'Y'
                  Else 'N'
            End
      , @Date - 364 --as SameWeekdayYearAgo
)
Select @Date = @Date + 1
End
0
 
LVL 34

Expert Comment

by:arbert
ID: 10872915
jandhb, did this help at all?
0
 
LVL 1

Author Comment

by:jandhb
ID: 10890832
arbert, thanks for that. i'm working with a team on this project and will have to get back with you soon about what you gave here. I can post back soon regarding this. Thank you for your help.

Just one question though....

1. What does the , symbol represent before many of the lines of code?

thanks.
0
 
LVL 34

Expert Comment

by:arbert
ID: 10891030
They're part of the insert statement and are place holders between the columns.....
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now