1、go--创建函数create function GetWeekDays(@year int)returns @t table (星期天varchar(20))asbegin insert @t select substring(convert(varchar,dateadd(day,x,col),120),1,10) from ( select cast(cast(@year as varchar(4))+'-1-1' as datetime) as col )a cross
2、 join ( select top 365b8.i+b7.i + b6.i + b5.i + b4.i +b3.i +b2.i + b1.i + b0.ix from(select 0i union all select 1) b0 cross join(select 0i union all select 2) b1 cross join(select 0i union all select 4) b2 cross join(select 0i union a
3、ll select 8) b3 cross join(select 0i union all select 16) b4 cross join(select 0i union all select 32) b5 cross join(select 0i union all select 64) b6 cross join(select 0i union all select 128) b7 cross join(select 0i union all select
4、256) b8 order by 1 )b where datepart(dw,dateadd(day,x,col))=1 returnend --测试示例select * from dbo.GetWeekDays(2011) --运行结果/*星期天--------------------2011-01-022011-01-092011-01-162011-01-232011-01-302011-02-062011-02-132011-02-202011-02-272011-03-0