I have the following integer type values in a SQL script: @year
, @month
, @day
. Now I want to convert those into a datetime value. Should be easy, right?
Well, I just went through the SQL documentation and was very surprised that I couldn't find any way to do this, other than converting to a string and then to a datetime.
declare @dt datetime
set @dt= convert(varchar,@year)+'/'+convert(varchar,@month)+'/'+convert(varchar,@day)
This is horrible! Surely there has to be a way to convert straight from the int values to the datetime?