日期:2014-05-18  浏览次数:20562 次

判断2个工作日的存储过程怎么写啊
根据一个时间字段,得到48小时后的一个时间(必须在工作日内,要去掉周末和法定假日),这个该怎么写啊?请高手帮忙下,谢谢了

------解决方案--------------------
declare @dt datetime
set @dt= '2007-6-3 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

set @dt= '2007-6-4 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

set @dt= '2007-6-5 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

set @dt= '2007-6-6 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

set @dt= '2007-6-7 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

set @dt= '2007-6-8 '
select @dt as sur,dateadd(day,
case datepart(weekday,@dt)
when 1 then 3
when 2 then 2
when 3 then 2
when 4 then 2
when 5 then 4
when 6 then 4
when 7 then 3
end
,@dt
) as result

------解决方案--------------------
以上只考虑周六周日

select identity(int,1,1) as id into # from syscolumns where id < 100

select * from #
--至少记录大于3条以上


declare @d datetime
set @d = '2006-6-6 '
select top 1 d,datepart(dw,d)
from (select dateAdd(day,ID, '2007-06-09 ') as d from #) a
where datediff(d,@d,d) > 0 and datepart(dw,d) > 1

drop table #
------解决方案--------------------
长假之前的周末要上班
这种情况很说不定,说不准是
长假之后的周末要上班