I have a dynamic stored procedure that includes the following input variables and Where condition with the column R.dateRec being formatted as datetime.
@rangeStart datetime,
@rangeEnd datetime
AND R.dateRec BETWEEN ' + @rangeStart + ' AND ' + @rangeEnd + '
When I run the procedure without this condition than it works well but when adding this it returns the following error, maybe because it doesn't recognise the values as dates:
Conversion failed when converting date and/or time from character string.
Can someone tell me how I can prevent this from happening ? The column in question only contains valid dates (no blank or NULL values).
Many thanks in advance, Tim.