日期:2014-05-18 浏览次数:20565 次
declare @ym varchar(7) set @ym='2011-01' set datefirst 1 select wk,MIN(d)d1,MAX(d)d2 from ( select DATEPART(wk,d)wk,d from ( select dateadd(D,number,@ym+'-01')d from master..spt_values where type='p' and convert(varchar(7),dateadd(D,number,@ym+'-01'),120)=@ym )t)t group by wk /* wk d1 d2 ----------- ----------------------- ----------------------- 1 2011-01-01 00:00:00.000 2011-01-02 00:00:00.000 2 2011-01-03 00:00:00.000 2011-01-09 00:00:00.000 3 2011-01-10 00:00:00.000 2011-01-16 00:00:00.000 4 2011-01-17 00:00:00.000 2011-01-23 00:00:00.000 5 2011-01-24 00:00:00.000 2011-01-30 00:00:00.000 6 2011-01-31 00:00:00.000 2011-01-31 00:00:00.000 (6 行受影响) */