So, pilots have to get so many flight hours and flight sorties within every 6 months (semi annual) as well as every year (annual). The biggest pain is that the start and ending dates of these periods are based upon their birth month.
You can find more information about my schema here: Design decision: Table schema for partial dates in order to calculate time spans (SQL Server)
DECLARE @date Date
SET @date = '1985-04-12'
DECLARE @diffInYears INT
SET @diffInYears = DATEDIFF(yy, @date, GETDATE())
DECLARE @currentBirthDate Date
SET @currentBirthDate = (SELECT dateadd(yyyy, @diffInYears, @date))
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@currentBirthDate)), DATEADD(m,7,@currentBirthDate)) semiAnnualDateEnd,
DATEADD(dd, -DAY(DATEADD(m,1,@currentBirthDate)), DATEADD(m,13,@currentBirthDate)) annualDateEnd
RESULTS:
semiAnnualDateEnd - annualDateEnd
2012-10-31 - 2013-04-30
Now, this is great, these are the dates I want for this particular example.
However, when we come to November 1st, 2012, I want the semiAnnualDateEnd to become 2013-04-30.
Also, when 2013 comes around (January 1st, 2013), the annualDateEnd is going to become 2014-04-30, when I want it to stay 2013-04-30 until 2013-05-01 comes around, and then for it to become 2014-04-30 (similar situation for the semiAnnual).
I don't want to keep these dates statically associated with a particular pilot. That is, I don't want to keep a couple fields in the Pilot table that have these. However, I want to use these for displaying and calculations. For example, going to need to display each pilot's current semiAnnual and annual sorties and flight hours, as well as displaying a snapshot their "current" stats at any particular point in time.
EDIT: I'm using SQL Server 2008 Express RC
EDIT 2: I'm thinking I should change the @currentBirthDate to (SELECT DATEADD(yyyy, @diffInYears - 1, @date). Then, I need to do a case statement below (continuing experimentation)