?
Solved

sql server 2000, data for a time dimension table

Posted on 2004-04-16
4
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
arbert earned 200 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

762 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