I need to display dates of all Mondays in the given date range.
For example, if my start date is 01/05/2015 and end date is 31/05/2015, I
01/05/2015
31/05/2015
Using a CTE it is possible this way..
DECLARE @DateFrom DateTime ='2015-05-01', @DateTo DateTime = '2015-05-31' ;WITH CTE(dt) AS ( SELECT @DateFrom UNION ALL SELECT DATEADD(d, 1, dt) FROM CTE WHERE dt < @DateTo ) SELECT 'Monday', dt FROM CTE WHERE DATENAME(dw, dt) In ('Monday')