I am testing my SQL Server script with date range and I have set up two variable Start and End date.
DECLARE @Start_Date DATETIME
DECLARE @End_Date DATETIME
SET @Start_Date = DateAdd(dd,-15,GETDATE())
SET @End_Date = DateAdd(dd,-1,GETDATE())
In Where part of script have I am filtering records :
Ord.[ORDER_START_Date_TIME] Between Convert(Varchar,@Start_Date,111) And Convert(Varchar,@End_Date,111)
If I set up SET @Start_Date = DateAdd(dd,-15,GETDATE())
It is working and bringing result, if I put days all way up to 19 it is working and bringing records back, when setup start date like:
SET @Start_Date = DateAdd(dd,-20,GETDATE())
I got error:
Msg 245, Level 16, State 1, Line 16
Conversion failed when converting the ****** value '******' to data type ******.
Any Idea what could be wrong?