December 2008
Mon Tue Wed Thu Fri Sat Sun
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

Day December 8, 2008

Get a Table of Months Between Two Dates

Sometimes you need a list of months between two dates. Admittedly, this is another case where a calendar table would come in VERY handy. Unfortunately, I have not been able to build one yet.

In case you’re in a similar situation, here’s how you could go about doing this:

CREATE FUNCTION dbo.GetMonthList (
  @StartDate DATETIME,
  @EndDate   DATETIME
)
RETURNS @months TABLE (
  [month] DATETIME
)
WITH EXECUTE AS OWNER AS
BEGIN
/******************************************************************************
 * Author:      Jeremiah Peschka
 * Create Date: 2008-11-20
 * Description: Create a table of dates between @StartDate and @EndDate
 *****************************************************************************/
  DECLARE @MonthDiff         INT;
  DECLARE @counter           INT;
  DECLARE @tbl               TABLE ([month] DATETIME);

  SET @StartDate = '2008-01-01';
  SET @EndDate   = '2008-12-01';

  SET @counter      = 0;

  SELECT @MonthDiff = DATEDIFF(mm, @StartDate, @EndDate);

  WHILE @counter <= @MonthDiff
  BEGIN
      INSERT @months
      SELECT (DATEADD(mm, @counter, @StartDate));

    SET @counter = @counter + 1;
  END

  RETURN;
END
GO

Links for the week

SQL Server

Anatomy of a Deadlock – Jonathan Kehayias outlines how deadlocks can occur, even in scenarios where they seemingly shouldn’t occur. I answered a question about this several weeks ago, but I couldn’t determine what the underlying cause of the deadlock was, I did not realize at the time that a SELECT would issue a Shared with Intent Exclusive lock on the table. (More on lock modes)

Showplan error – Tom LaRock delves into an execution plan oddity: Are you a member of sysadmin? Can’t get an execution plan for some reason? EXECUTE AS might be the culprit.

Development

Ext Framework, jQuery and ASP.NET – Daniel Penrod outlines how to approach using either the Ext or jQuery framework within your ASP.NET applications. JavaScript isn’t scary. jQuery makes JavaScript exceptionally easy and, dare I say it, fun.

Using System.Web.Abstractions in Your WebForms Apps – Justin Etheredge covers how to make use of the new ASP.NET MVC classes in a traditional web forms application. Why might you want to do this? Testing and mocking, of course!

General

Big Three: Clean up your dealerships – Jason Fried (of 37signals) recently purchased a new car and writes about the appearance of the individual dealerships he visited. Appearances matter, especially on something like a car purchase.

Keeping Your Head In The Cloud – Jeff Blankenburg creates a fictional t-shirt company, becomes wildly successful, begins selling to China, and solves his concurrency and uptime issues with Windows Azure!

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 401 items have been purified.