My Blog List

hotinit.com. Powered by Blogger.

Search This Blog

Display Dates Between Two Dates in Sql Server

Thursday, 15 September 2011



DECLARE @StartDate DATETIME
SET @StartDate = '02/26/1988'

DECLARE @EndDate DATETIME
SET @EndDate = '03/01/1988'

DECLARE @TableOfDates TABLE(DateValue DATETIME)

DECLARE @CurrentDate DATETIME

SET @CurrentDate = @startDate

WHILE @CurrentDate <= @endDate
BEGIN
    INSERT INTO @TableOfDates(DateValue) VALUES (@CurrentDate)

    SET @CurrentDate = DATEADD(DAY, 1, @CurrentDate)
END

SELECT * FROM @TableOfDates

No comments:

Post a Comment

 

Blogger news

Blogroll

Most Reading

8.6/10