I have the following WHERE clause in a SELECT statement.
WHERE (Appointment_Dt BETWEEN DATEADD(d, 14, CONVERT(CHAR(10),GETDATE(),101)) AND DATEADD(d, 28, CONVERT(CHAR(10),GETDATE(), 101)))
The statement takes about 15 minutes to run. If I change it to
WHERE (Appointment_Dt BETWEEN DATEADD(d, 14, '3/24/2009') AND DATEADD(d, 28, '3/24/2009'))
it takes 2 seconds. I have tried moving the hard coded date to a declared variable, and replecing it in the WHERE clause with the declared variable, but it still takes about 15 minutes to run.
Any ideas of what could be happening and, in particular, how to get it to run faster with variables in the SQL statement?
WHERE (Appointment_Dt BETWEEN DATEADD(d, 14, CONVERT(CHAR(10),GETDATE(),101)) AND DATEADD(d, 28, CONVERT(CHAR(10),GETDATE(), 101)))
The statement takes about 15 minutes to run. If I change it to
WHERE (Appointment_Dt BETWEEN DATEADD(d, 14, '3/24/2009') AND DATEADD(d, 28, '3/24/2009'))
it takes 2 seconds. I have tried moving the hard coded date to a declared variable, and replecing it in the WHERE clause with the declared variable, but it still takes about 15 minutes to run.
Any ideas of what could be happening and, in particular, how to get it to run faster with variables in the SQL statement?