hello I was looking to execute a stored procedure that receives variables for @startweek and @endweek.
I wanted to pass for execution that the @endweek to be the last friday of the current week and for the @startweek to be the friday of 6 weeks ago.
I have made the following for the last friday of current week:
SELECT @startweek = '25 Jan 2019'
SELECT @endweek = DATE
FROM
(SELECT DATE = dateadd(d, -((datepart(weekday, getdate()) + 1 + @@DATEFIRST) % 7), getdate())) a
ORDER BY a.DATE DESC
What I'm needing to do is to get the way to pass the @endweek value (now is hardcoded) for it to select the last friday of 6 weeks ago.
one thing that I got to work is the following:
SELECT friday4WeeksAgo =dateadd(ww, -4,DATE)
FROM
(SELECT DATE = dateadd(d, -((datepart(weekday, getdate()) + 1 + @@DATEFIRST) % 7), getdate())) a
ORDER BY a.DATE DESC
but I wasn't able to pass this to a variable
I have the procedure written, just need to figure out how to do to pass to these variable the values that I need (@startweek and @endweek) to show the last friday from 6 weeks ago and the last friday from current week
thank you for any help