declare @start datetime,
@end datetime,
@zoomOutStart datetime,--放大指数
@zoomOutEnd datetime,
@zoomOutStartSpan int,
@zoomOutEndSpan int,--
@zoomOutTimeSpan int,--放大的时间距离
@zoomOutWeekCount int,--时间段内的周未天数
@workTime int--时间段内的工作天数
SET @start='2011-2-5'--起始时间
SET @end=DATEADD(MS,-2, DATEADD(DD,30,@start))--结束时间
SET @zoomOutStartSpan=DATEPART(WEEKDAY,@start)-1
SET @zoomOutEndSpan=7-DATEPART(WEEKDAY,@end)
SET @zoomOutStart=DATEADD(DD,-1*@zoomOutStartSpan,@start)
SET @zoomOutEnd=DATEADD(DD,@zoomOutEndSpan,@end)
SET @zoomOutTimeSpan=DATEDIFF(DD,@zoomOutStart,@zoomOutEnd)+1
SET @zoomOutWeekCount=@zoomOutTimeSpan/7*2--时间放大后的周未天数
SET @workTime=@zoomOutTimeSpan/7*5--工作时间
IF @zoomOutStartSpan>0
BEGIN
set @zoomOutWeekCount=@zoomOutWeekCount-1
set @workTime=@workTime-@zoomOutStartSpan+1
END
IF @zoomOutEndSpan >0
BEGIN
set @zoomOutWeekCount=@zoomOutWeekCount-1
set @workTime=@workTime-@zoomOutEndSpan+1
END
IF @zoomOutWeekCount<0
set @zoomOutWeekCount=0
SELECT @start,@end,
@zoomOutStart,@zoomOutEnd,
@zoomOutStartSpan,@zoomOutEndSpan,
@zoomOutTimeSpan,
@zoomOutWeekCount,@workTime