Add datetime and time
sql, sql-server-2012
Solution
The above code will work with MS SqlServer 2008 but this code won't work with MS SqlServer 2012 or above. I have encountered the same issue and solve it like this.
DECLARE @today_start datetime
DECLARE @dail_time time
SELECT @today_start = convert(datetime, @dayStr,103) + CAST(@dail_time as DATETIME)
Problem
Server: SQL Server 2012; SP1; Developer Edition Code: ``` declare @datetime datetime = '1900-01-01 00:00:00.000' declare @time time = '11:11:11' select @datetime + @time ``` When I run the above code in the `MASTER` database, I get the error: Msg 402, Level 16, State 1, Line 3 The data types datetime and time are incompatible in the add operator. But when it's any other database, it works! Any idea why this must be happening? P.S. - In the enterprise edition, this throws an error irrespective of the database context.