日期:2014-05-18 浏览次数:20508 次
if object_id('proc_test') is not null drop procedure proc_test go create procedure proc_test @starttime datetime, @endtime datetime as begin select 日期=convert(varchar(10),date,120),星期=week from ( select date=dateadd(dd,number,@starttime),week=datename(weekday,dateadd(dd,number,@starttime)) from master..spt_values where type='p' and dateadd(dd,number,@starttime)<@endtime )t where week='星期六' end go exec proc_test '2010-10-01','2010-10-31' /* 日期 星期 ----------------------- 2010-10-02 星期六 2010-10-09 星期六 2010-10-16 星期六 2010-10-23 星期六 2010-10-30 星期六 */
------解决方案--------------------
我稍改一下 if object_id('proc_test') is not null drop procedure proc_test go create procedure proc_test @starttime datetime, @endtime datetime as begin select 日期=convert(varchar(10),date,120),星期=week from ( select date=dateadd(dd,number,@starttime),week=datename(weekday,dateadd(dd,number,@starttime)) from master..spt_values where type='p' and number between 0 and datediff(day,@starttime,@endtime) )t where week='星期六' end go exec proc_test '2010-10-01','2010-10-31'