I only have access to SQL 2008R2 at work, so you can count on this working in all versions of sql server.
Try this (caveat - not extensively tested, but for the testdate indicated, it returns Friday 8/30/2018, and for the next month it returns Monday 04/30/2018):
SET DATEFIRST 1;
declare @testDate date = '03/21/2018';
declare @lastWorkDay date = CASE WHEN DATEPART(WEEKDAY, DATEADD(DAY,-1,DATEADD(month, DATEDIFF(month, 0, @testdate) + 1, 0))) <= 5
THEN DATEADD(DAY,-1,DATEADD(month, DATEDIFF(month, 0, @testdate) + 1, 0))
ELSE DATEADD(DAY,-(7-DATEPART(WEEKDAY, DATEADD(DAY,-1,DATEADD(month, DATEDIFF(month, 0, @testdate) + 1, 0)))+1),DATEADD(month, DATEDIFF(month, 0, @testdate) + 1, 0))
END;
select @lastWorkDay;
Of course, I can't test this until I get home, but there's the code for sql server 2012 and higher . If you are running 2012 or higher, simply replace the code above following code:
declare @lastWorkDay date = CASE WHEN DATEPART(WEEKDAY, EOMONTH(@testDate)) <= 5
THEN EOMONTH(@testDate)
ELSE DATEADD(DAY, -(7-DATEPART(WEEKDAY, EOMONTH(@testDate))),EOMONTH(@testDate))
END
EDIT ============================
NOTE: All of the code above has been corrected and verified to run in sql server 2012+.