Please help me to find out error in my SQL query. I have created this query to compare dates
select * from Joinplans jp
where cast(convert(varchar,GETDATE(),103) AS datetime) BETWEEN
CASE(convert(varchar,jp.planstartDate,103) AS datetime) AND
CASE(convert(varchar,DATEADD(DAY,jp.planDays,jp.planstartDate),103) AS DATETIME)
It’s giving me the error:
incorrect near ‘AS’
I am using SQL Server 2005.
If planStartDate is actually a date, then there is no need to cast it to a character column:
Now, if planStartDate is storing both date and time data, then you might want to use something like:
This ensures that all times on the last date calculated via the DateAdd function are included