Logic is here:
SQL SERVER – Query to Find First and Last Day of Current Month[
^]
Check this:
DECLARE @startdate DATE = GETDATE()
SET @startdate = DATEADD(MM, -3, DATEADD(DD, -DAY(@startdate)+1, @startdate))
DECLARE @enddate DATE = DATEADD(MM, 4, @startdate)
SELECT CONVERT(DATETIME, @startdate) AS StartDate, CONVERT(DATETIME, @enddate) AS EndDate
Above query returns:
StartDate EndDate
2015-02-01 00:00:00.000 2015-06-01 00:00:00.000
In your case,
WHERE
statement must be changed as follow:
WHERE ord_l.EST_PICK_DATE BETWEEN @startdate AND @enddate