Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql server 2000, data for a time dimension table

Posted on 2004-04-16
4
Medium Priority
?
316 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 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

971 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