I have a stored proceedure that runs a report that automatically fills in the date variable. I planned to have a change when the end of the year came around, and now the report won't work. I can't see the problem. Perhaps someone can give this code a quick look over and see what the problem is. I am getting an error Syntax error converting datetime from character string. Here is the code, and thanks.
DECLARE @start_date datetime
DECLARE @finish_date datetime
DECLARE @last_month datetime
SET @last_month = DATEADD(mm,-1,GetDate())
SET @start_date = CONVERT(datetime,STR(MONTH(@last_month))+'/01/'+
STR(YEAR(@last_month)),101)
IF MONTH(@last_month)<12
SET @finish_date = DATEADD(day,-1,CONVERT(datetime,STR(MONTH(@last_month)+1,2)
+'/01/'+STR(YEAR(@last_month)),101))
ELSE
SET @finish_date=DATEADD(day,-1,convert(datetime,'01/01/'+STR(YEAR(@last_month)+1)+'23:59:00',101))
DECLARE @start_date datetime
DECLARE @finish_date datetime
DECLARE @last_month datetime
SET @last_month = DATEADD(mm,-1,GetDate())
SET @start_date = CONVERT(datetime,STR(MONTH(@last_month))+'/01/'+
STR(YEAR(@last_month)),101)
IF MONTH(@last_month)<12
SET @finish_date = DATEADD(day,-1,CONVERT(datetime,STR(MONTH(@last_month)+1,2)
+'/01/'+STR(YEAR(@last_month)),101))
ELSE
SET @finish_date=DATEADD(day,-1,convert(datetime,'01/01/'+STR(YEAR(@last_month)+1)+'23:59:00',101))