Hi,
First of all, I'm assuming that you're using
SQL Server. Here's an example (the query should work in
SQL Server 2005 or above):
DECLARE @Year VARCHAR(4),
@Month VARCHAR(3),
@FirstDate DATETIME,
@LastDate DATETIME;
SET @Year = '2014';
SET @Month = '07';
SET @FirstDate = (SELECT CAST(( @Year + @Month + '01' ) AS DATETIME));
SET @LastDate = DATEADD(DAY, -1, ( DATEADD(MONTH, 1, @FirstDate) ));
;WITH Fridays([Date])
AS (SELECT [Date] = @FirstDate
UNION ALL
SELECT [Date] = DATEADD(DAY, 1, [Date])
FROM Fridays
WHERE [Date] < @LastDate)
SELECT [Date]
FROM Fridays
WHERE DATENAME(WEEKDAY, [Date]) = 'Friday';
Note: This query could (should) be improved considering your input parameters and version of the
SQL Server.
Result:
Date
2014-07-04 00:00:00.000
2014-07-11 00:00:00.000
2014-07-18 00:00:00.000
2014-07-25 00:00:00.000
Please let me know if you need further assistance.