dbTalk Databases Forums  

Help with creating time dimension

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Help with creating time dimension in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris
 
Posts: n/a

Default Help with creating time dimension - 09-17-2006 , 02:41 PM






Hi,
Where can I find information on creating a time dimension o display my data
for different periods.

I am collecting orders (in my OLAP Server) as in the sample below

OrderID CustID ProdID Qty Price DateOrdered
12343 ABC455 12003 1 1.00 2006-01-01
15543 AZC475 19943 3 5.00 2006-02-01
12333 ABQ415 55343 1 1.00 2006-03-01
12243 BBC255 66343 2 2.00 2006-04-01
12773 AZC475 12343 1 1.00 2006-05-01

How do I apply a time dimension to sort by Year, Quarter, Month, Week,
Day(s)? Does his need to be in a separate tabel? Where can I find some
samples?

Thanks

Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Help with creating time dimension - 09-17-2006 , 10:49 PM






If you're using AS 2005, a Server Time Dimension can be created, without
a separate time table:

http://msdn2.microsoft.com/en-us/library/ms174832.aspx
Quote:
SQL Server 2005 Books Online
Defining a Server Time Dimension

A time dimension in Microsoft SQL Server 2005 Analysis Services (SSAS)
can be based either on a table in a data source view or on a date range.
A time dimension that is based on a table is really no different from
any other standard dimension. Its attributes are bound to columns of a
dimension table just like any other standard dimension.

In contrast, a range-based time dimension is typically used when there
is no separate time table to define time periods. Attributes of a
range-based time dimension have time-attribute bindings, which define
the attributes according to specified time periods such as Years,
Months, Weeks, or Days. Because the data for a range-based time
dimension is created and stored on the server instead of coming from any
table in the data source, a range-based time dimension is called a
server time dimension.
...
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
  #3  
Old   
Chris
 
Posts: n/a

Default Re: Help with creating time dimension - 09-18-2006 , 09:59 AM



Hi,
I am using SQL 2000 AS. I guess I'll have to create a separate table with
the time-data data and then map to my fact table. Where can I find sample of
time dimension data table? I am looking to track by Year, Quarter, Month,
Week, Days, Holidays.

Thanks

"Deepak Puri" wrote:

Quote:
If you're using AS 2005, a Server Time Dimension can be created, without
a separate time table:

http://msdn2.microsoft.com/en-us/library/ms174832.aspx

SQL Server 2005 Books Online
Defining a Server Time Dimension

A time dimension in Microsoft SQL Server 2005 Analysis Services (SSAS)
can be based either on a table in a data source view or on a date range.
A time dimension that is based on a table is really no different from
any other standard dimension. Its attributes are bound to columns of a
dimension table just like any other standard dimension.

In contrast, a range-based time dimension is typically used when there
is no separate time table to define time periods. Attributes of a
range-based time dimension have time-attribute bindings, which define
the attributes according to specified time periods such as Years,
Months, Weeks, or Days. Because the data for a range-based time
dimension is created and stored on the server instead of coming from any
table in the data source, a range-based time dimension is called a
server time dimension.
...



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
  #4  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Help with creating time dimension - 09-18-2006 , 08:13 PM



There are some previous Newsgroup posts with sample SQL scripts for
creating date/time tables. But I don't think that they flag holidays -
here's an example:

http://groups.google.com/group/micro...datawarehouse/
msg/972edd58f55931ed?hl=en&
Quote:
microsoft.public.sqlserver.datawarehouse > Date/Time Dimension Table

You can use this -

CREATE TABLE [dbo].[time_dimension] (
[time_id] [int] IDENTITY (1, 1) NOT NULL ,
[the_date] [datetime] NULL ,
[the_day] [nvarchar] (15) NULL ,
[the_month] [nvarchar] (15) NULL ,
[the_year] [smallint] NULL ,
[day_of_month] [smallint] NULL ,
[week_of_year] [smallint] NULL ,
[month_of_year] [smallint] NULL ,
[quarter] [nvarchar] (2) NULL ,
[fiscal_period] [nvarchar] (20) NULL
) ON [PRIMARY]

DECLARE @WeekString varchar(12),
@dDate SMALLDATETIME,
@sMonth varchar(20),
@iYear smallint,
@iDayOfMonth smallint,
@iWeekOfYear smallint,
@iMonthOfYear smallint,
@sQuarter varchar(2),
@sSQL varchar(100),
@adddays int

SELECT @adddays = 1 --Incrementing the days by one
SELECT @dDate = '01/01/1960' --The start date

WHILE @dDate < '12/31/2000' --End Date
BEGIN

SELECT @WeekString = DATENAME (dw, @dDate)
SELECT @sMonth=DATENAME(mm,@dDate)
SELECT @iYear= DATENAME (yy, @dDate)
SELECT @iDayOfMonth=DATENAME (dd, @dDate)
SELECT @iWeekOfYear= DATENAME (week, @dDate)
SELECT @iMonthOfYear=DATEPART(month, @dDate)
SELECT @sQuarter = 'Q' + CAST(DATENAME (quarter, @dDate)as
varchar(1))
INSERT INTO time_dimension(the_date, the_day, the_month, the_year,
day_of_month,
Week_of_year, month_of_year, quarter) VALUES
(@dDate, @WeekString, @sMonth, @iYear, @iDayOfMonth, @iWeekOfYear,
@iMonthOfYear, @sQuarter)
SELECT @dDate = @dDate + @adddays
END
GO


Best Regards

Trevor Dwyer - SQL Server MVP
...
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.