SQL Server function DATEFROMPARTS for pre 2012 versions

SQL Server function for SQL 2000, 2005, 2008 and 2008R2 for same functionality as the 2012 function DATEFROMPARTS

About

This is a fairly simple function to replace the missing functionality of the DATEFROMPARTS function in SQL Server 2012 and later.

It is a simple concatenation of the year, month and day into a date format, and returned as a date. Once built call it as you would any other function.

SQL

CREATE FUNCTION DateFromParts(@Year SMALLINT, @Month SMALLINT,@Day SMALLINT) RETURNS DATE AS BEGIN
DECLARE
@Date DATE=CONVERT(NVARCHAR(4),@Year)+'-'+CONVERT(NVARCHAR(2),@Month)+'-'+CONVERT(NVARCHAR(2),@Day)
RETURN @Date
END
Ousia Logo