计算时间段内的工作日的SQL_SERVER脚本

DECLARE @WeekDay INT,@WorkDays INT,@StartDate datetime,@EndDate datetime,@Date datetime
SET @StartDate = getdate()
SET @EndDate = '2008-4-26'
SET @Date = @StartDate

SET @WorkDays = 0
WHILE (@Date < @EndDate)
BEGIN
 SET @WeekDay = DATEPART(WEEKDAY,  @Date)

 IF @WeekDay <> 1 AND @WeekDay  <> 7
  SET @WorkDays = @WorkDays + 1

 SET @Date = DATEADD(DAY, 1, @Date)
END
print @WorkDays

posted on 2008-08-17 23:38  Sanle  阅读(259)  评论(0编辑  收藏  举报

导航