Month Variable Table

Every once in a while you need a quick Table w/ a range of dates, that's what this is for...


Declare @iLoop AS INT
SET @iLoop = 0
DECLARE @rptMonths TABLE(rptMonth DateTime)
WHILE @iLoop <= DateDiff(mm, @StartDate, @EndDate)
BEGIN
INSERT INTO @rptMonths(rptMonth) VALUES(DATEADD(mm, @iLoop, @StartDate))
SET @iLoop = @iLoop + 1
END

Comments

Popular posts from this blog

Service Broker and External Activator for Sql Server...

List to Table

Turbo Charge Your SSMS