﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Bhudev Prakash  / Date Dimensions in T-SQL using CTE / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 20 Jun 2013 05:22:14 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Excellent code.  Thanks !  :-)  :)</description><pubDate>Thu, 08 Jul 2010 21:08:27 GMT</pubDate><dc:creator>Yimmy.Rengifo</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Hi Ricky,Please remove special characters and then check, it should work, When I put my code, it was tab for me, but it seems that Script editor has changed it to something else.RegardsBhudev</description><pubDate>Tue, 06 Jul 2010 07:05:14 GMT</pubDate><dc:creator>Bhudev Prakash</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>I tried to execute the code again but still its not working Now Its Giving error in the section given belowINSERT INTO DimTimeSELECT 	TimeKey,    TimeFullDate,    TimeDayNumberOfWeek,especially for TimeKey and TimeFullDate</description><pubDate>Tue, 06 Jul 2010 03:08:01 GMT</pubDate><dc:creator>ricky70rana</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Hi wildhAs I included URLs of several Time Dimension discussions, I think all are good enough to produce Time Dim, and infect I picked my base query one of them only and enhance little bit as per my need.Regarding[color=#345][quote]Does anyone else include descriptions apart form day and month? I know descriptions can be constructed in analysis services when creating the dim but I choose to keep descriptions like ‘Fri 01/01/2010’ and ‘Jan 2010’ and even ‘11:59 pm - 12:00 am’ in the relative date and time dimension and include that field as the dimension description. I didn’t choose this approach for performance or disc space I chose it for personal preference.[/quote][/color]It depends on Project-to-Project requirement how it requires displaying the description, someone will like JAN 2010JAN – 20102010 - JANJanuary 2010January – 20102010 - JanuaryAnd again depends on their grain level, may be Week, may be Month or may be bi-weekly. So as per my understanding, it is based on requirement at which level it requires to see description and in what format. On the other hand, in retail industry, client may give you their own rule for showing descriptions, hence is better to keep base Time table and top of that VIEW or in SSAS description can be added as per decision/design.</description><pubDate>Mon, 05 Jul 2010 23:29:55 GMT</pubDate><dc:creator>Bhudev Prakash</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Hi, These are the points based on that you may getting error meesage:1. DATEFORMAT is set to MDY and you are storing as date in DMY format.2. You may use OPTION (MAXRECURSION 0) opetion to avoid following error message, as default recursion is 100.Msg 530, Level 16, State 1, Line 5The statement terminated. The maximum recursion 100 has been exhausted before statement completion.Please check following, it should work for you.SET DATEFORMAT DMY;DECLARE @StartDate DATETIME = '01-01-2010';DECLARE @EndDate DATETIME = '31-12-2010';WITH DateCTE AS(	SELECT TimeKey = CONVERT(INT,(CONVERT(VARCHAR(10),@StartDate,112))),		FullDate = @StartDate 	UNION ALL	SELECT 		TimeKey = CONVERT(INT,(CONVERT(NVARCHAR(10),FullDate + 1,112))),		FullDate = FullDate + 1 	FROM DateCTE 	WHERE FullDate + 1 &amp;lt; = @EndDate )SELECT * FROM DateCTE OPTION (MAXRECURSION 0);I hope it will help.</description><pubDate>Mon, 05 Jul 2010 23:03:51 GMT</pubDate><dc:creator>Bhudev Prakash</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>I always read articles about date and time dimensions; just to see how they compare to the script I take with me wherever I go, just to see if there’s something else I could incorporate or do different. Recently (based on articles I’ve seen here, apart form ‘The Sins of Old: Time_T’, which was fun reading the discussion) I’ve been questioning some of the things I include in my date and time dimension.Does anyone else include descriptions apart form day and month? I know descriptions can be constructed in analysis services when creating the dim but I choose to keep descriptions like ‘Fri 01/01/2010’ and ‘Jan 2010’ and even ‘11:59 pm - 12:00 am’ in the relative  date and time dimension and include that field as the dimension description. I didn’t choose this approach for performance or disc space I chose it for personal preference.So I was wondering does anyone else keep their dimension ‘long descriptions’ in their SQL tables and if not is there a reason?</description><pubDate>Mon, 05 Jul 2010 02:57:38 GMT</pubDate><dc:creator>wildh</dc:creator></item><item><title>RE: Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Your code is not working as tried to execute in SQL SERVER 2008. Its showing some syntax error in the code section  given below :SET DATEFORMAT MDY;DECLARE @StartDate DATETIME = '01-01-2010';DECLARE @EndDate DATETIME = '31-12-2020';WITH DateCTE AS(    SELECT TimeKey = CONVERT(INT,(CONVERT(VARCHAR(10),@StartDate,112))),         FullDate = @StartDate       UNION ALL    SELECT        TimeKey =  CONVERT(INT,(CONVERT(NVARCHAR(10),FullDate + 1,112))),        FullDate =  FullDate + 1     FROM DateCTE     WHERE FullDate + 1 &amp;lt; = @EndDate )SELECT * FROM DateCTE ;</description><pubDate>Mon, 05 Jul 2010 02:49:34 GMT</pubDate><dc:creator>ricky70rana</dc:creator></item><item><title>Date Dimensions in T-SQL using CTE</title><link>http://www.sqlservercentral.com/Forums/Topic937152-2595-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/time+dimension/70488/"&gt;Date Dimensions in T-SQL using CTE&lt;/A&gt;[/B]</description><pubDate>Mon, 14 Jun 2010 15:09:35 GMT</pubDate><dc:creator>Bhudev Prakash</dc:creator></item></channel></rss>