Translate

Tuesday, January 24, 2012

Select all months bewtween two dates



 No loops... no recurrsion... nice tight code...

;with Numbers (Number) as
 (select row_number() over (order by object_id)
 from sys.all_objects)
select dateadd(month, number, @StartDate)
from Numbers
where number <= datediff(month, @StartDate, @EndDate)

No comments:

Post a Comment