The following function returns the Nth occurance of week day in a month IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME =’GetNthWeekday’ AND ROUTINE_SCHEMA = ‘dbo’ AND ROUTINE_TYPE=’FUNCTION’)DROP FUNCTION dbo.GetNthWeekdayGOCREATE FUNCTION dbo.GetNthWeekday(@date datetime,–Any date of month under consideration@N int,– Nth…