a different approach
you can have a separate table to store all the dates, just like a Date dimension table and then in your main table have a foreign key pointing to it
CREATE TABLE YourDatesTable (
DateID int NOT NULL IDENTITY(1, 1),
[Date] datetime NOT NULL,
[Year] int NOT NULL,
[Month] int NOT NULL,
[Day] int NOT NULL
CONSTRAINT PK_Dates PRIMARY KEY CLUSTERED (DateID)
)
Set the Dates Start and End
DECLARE @StartDate datetime
DECLARE @EndDate datetime
SET @StartDate = '01/01/1955'
SET @EndDate = '12/31/2004'
Generate the Date Records
DECLARE @LoopDate datetime
SET @LoopDate = @StartDate
WHILE @LoopDate <= @EndDate
BEGIN
INSERT INTO YourDatesTable VALUES (
@LoopDate,
Year(@LoopDate),
Month(@LoopDate),
Day(@LoopDate)
)
SET @LoopDate = DateAdd(d, 1, @LoopDate)
END
View the Dates and notice that leap years have feb 29 and non leap years have only till feb 28
a non leap year
SELECT * FROM YourDatesTable
where Month = 2
and Year = 2003
a leap year
SELECT * FROM YourDatesTable
where Month = 2
and Year = 2004
you can use the DateID as a foreign key in your main table
This way you have day, month and year seperate and you also have the Date in dateformat for any date related functions
for reference
the script to generate a date dimension i used this site
http://www.sqlbook.com/Data-Warehousing/Date-Dimension-SQL-script-18.aspx