<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Slayer &#187; Dimensional Modeling</title>
	<atom:link href="http://www.sqlslayer.com/wp/tag/dimensional-modeling/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlslayer.com/wp</link>
	<description>Making SQL do what we want it to do.</description>
	<lastBuildDate>Mon, 12 Dec 2011 13:53:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generating a Date Dimension the easy way</title>
		<link>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/</link>
		<comments>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 02:02:50 +0000</pubDate>
		<dc:creator>buckleyc</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Data Warehouse]]></category>
		<category><![CDATA[Date Dimension]]></category>
		<category><![CDATA[Dimensional Modeling]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=106</guid>
		<description><![CDATA[<p>While there are different views on how to build different dimensions, there seems to be a common view of how, at least the basic information, of date dimensions looks. This can take a little time to build out. To help in building this dimension, I created a simple table valued function that takes in a [...]]]></description>
			<content:encoded><![CDATA[<p>While there are different views on how to build different dimensions, there seems to be a common view of how, at least the basic information, of date dimensions looks. This can take a little time to build out. To help in building this dimension, I created a simple table valued function that takes in a start date and returns a date dimension table.</p>
<blockquote><pre>
/*******************************************************************************************************
** Name: dbo.GenerateDateDimension
** Desc: Takes a start date and returns all dates up to the current day as a Date Dimension table.
** Auth: Cliff Buckley (SQLSlayer.com)
** Parameters: @StartDate - The starting date for the date dimension table.
** Dependancies: None
** Notes:
** Date: 10.07.2009
** Example: SELECT * FROM dbo.GenerateDateDimension('1/1/2009')
*******************************************************************************
** Change History
*******************************************************************************
** Date: Author: Description:
** -------- -------- ---------------------------------------
**
********************************************************************************************************/
CREATE FUNCTION dbo.GenerateDateDimension
(
@StartDate datetime
)
RETURNS @DimDate TABLE(DateId int,YearNumber smallint, QuarterNumber tinyint, MonthText varchar(20)
,MonthNumber tinyint,DayNumberOfMonth tinyint, DayOfWeekText varchar(20)
,DayNumberOfYear smallint,SQLDate datetime)
AS
BEGIN
DECLARE @EndDate datetime

SET @EndDate = CAST(CONVERT(varchar(8),getdate(),112) as datetime)

WHILE @StartDate &lt;= @EndDate
BEGIN
INSERT INTO @DimDate(DateId,YearNumber,QuarterNumber,MonthText,MonthNumber,DayNumberOfMonth,DayOfWeekText,DayNumberOfYear,SQLDate)
SELECT CAST(CONVERT(varchar(8),@StartDate,112) AS INT) AS DateId
,DATENAME(year,@StartDate) AS YearNumber
,DATENAME(quarter,@StartDate) AS QuarterNumber
,DATENAME(month,@StartDate) AS MonthText
,MONTH(@StartDate) AS MonthNumber
,DATENAME(day,@StartDate) AS DayOfMonthNumber
,DATENAME(weekday,@StartDate) AS DayOfWeekText
,DATENAME(dayofyear,@StartDate) AS DayNumberOfYear
,@StartDate AS SQLDate
SET @StartDate = DATEADD(d, 1, @StartDate)
END

RETURN;
END
GO
</pre>
</blockquote>
<p>Unfortunately, the formatting is lost, but you get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

