March 18, 2014 at 10:34 am
I have code below not working in SQL 2012
declare @d1, @d2, @d3 datetime
...where @d1 between (@d2-15) and (@d3 + 15)
Error:
Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query
How to fix it?
March 18, 2014 at 10:41 am
Use DATEADD
declare @d1, @d2, @d3 datetime
...where @d1 between DATEADD(DD,-15,@d2) and DATEADD(DD,15,@d3)
March 19, 2014 at 4:25 am
For more info on all the date and time functions check out the documentation at Microsoft.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply