DATEFROMPARTS() returns a date value for the specified year, month, and day.
Let us understand this with an example.
The SQL code for returning day, month and year parameters as a date would probably look something like this
DECLARE @Day INT = 07, @Month int = 03,@Year INT = 2014 SELECT CONVERT(datetime,CONVERT(varchar(10),@Year) + '-' + CONVERT(varchar(10),@Month) + '-' + CONVERT(varchar(10),@Day),103) AS TheDate
Now lets implement DATEFROMPARTS
Here is the code for the same
DECLARE @Day INT = 07, @Month int = 03, @Year INT = 2014 SELECT DATEFROMPARTS (@Year, @Month, @Day) AS TheDate
Tagged: Analytical functions in SQL Server 2012, Date and time functions, datefromparts(), New Analytical functions in SQL Server 2012, New features in SQL Server 2012, New Functions in SQL Server 2012, Programming, T-Sql
Leave a Reply