I have a stored procedure that I want to 1st gather data between a @startdate
& @enddate
then I want to compare that data to the previous year.
I tried the below syntax (for testing obviously) to ensure I was getting my desired dates output before I added to my production syntax. However, this gives me an error of
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near '–'.
Msg 102, Level 15, State 1, Line 14
Incorrect syntax near '–'.
This is the syntax I tried. What would I alter in order for my required dates to be output?
Declare @startdate date = '20170101'
,@enddate date = '20170212'
--one year prior to @startdate
Select CAST(DateAdd(yy, -1, @startdate) As Date)
--One year prior to @enddate
SELECT CAST(DateAdd(yy, -1, @enddate) As Date)
--This will get first day of prev yr
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0,
DATEADD(YEAR, –1, @startdate)), 0)
--This will get last day of prev yr
SELECT DATEADD(MILLISECOND, –3, DATEADD(YEAR,
DATEDIFF(YEAR, 0, DATEADD(YEAR, –1, @enddate)) + 1, 0))
EDIT
What I want to return is
01/01/2017
02/12/2017
01/01/2016
12/31/2016