I'm stuck on the last Sunday at the moment but here's how you handle the first Monday.
Lynn Pettis has a great post about common date routines. I turned some of those routines into inline table valued functions. Here's a function that returns the first day of the month: CREATE FUNCTION dbo.firstOfMonth (@date datetime, @months smallint)
RETURNS TABLE WITH SCHEMABINDING AS RETURN
SELECT monthStart = dateadd(mm,datediff(mm,0,@date)+@months,0);
GO
And one that returns the first business day of the week (Monday)CREATE FUNCTION dbo.firstOfWeek (@date datetime, @weeks smallint)
RETURNS TABLE WITH SCHEMABINDING AS RETURN
SELECT weekStart = dateadd(wk,datediff(wk,0,@date)+@weeks,0);
GO
To get the first Monday of the week of the month you can do this:SELECT firstMonday = w.weekStart
FROM dbo.firstOfMonth(GETDATE(), 0) m
CROSS APPLY dbo.firstOfWeek(m.monthStart, 0) w;
For this month the first Monday as 2018-05-28 which is what you were looking for.
Like I said, I'm a little stuck on the Sunday part (and out of time) but, this returns the correct answer (2018-07-01) for this month:SELECT w.weekStart-1
FROM dbo.firstOfMonth(GETDATE(), 1) m
CROSS APPLY dbo.firstOfWeek(m.monthStart, 0) w;
But for other months the correct calculation would be to replace w.weekStart-1 with w.weekStart+6. To push this across the finish line you can build a CASE statement which returns either w.weekStart-1 or w.weekStart+6 based on something I can't figure out at the moment.
-- Itzik Ben-Gan 2001