Can someone tell me what I am doing wrong. When I run the query I get the '01/14/2014' date over and over again. I was looking to get every Friday's date for 2013. Is there an easier way to do this?
Thanks!
DECLARE @date varchar(10); SET @date='01/07/2013'; WHILE @date < Convert(datetime, '01/07/2014') BEGIN SELECT CASE WHEN DATEADD(dd,(DATEDIFF(dd,0, @date)/7)* 7,0) + 5 < @date THEN (CONVERT(VARCHAR(10),(DATEADD(dd,(DATEDIFF(dd,0,@date)/7)* 7,0) + 5),101)) ELSE (CONVERT(VARCHAR(10),(DATEADD(dd,(DATEDIFF(dd,0,@date)/7)* 7,0) -3),101)) END as Friday_MM_DD_YYYY; SET @date = (SELECT DATEADD(day, 7,(Convert(date, '01/07/2013')))); print (@date) END;