计算时间段内的工作日的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

你可能感兴趣的:(server)