SQL 日历
declare @dt datetime
set @dt = '2010-12-15'
;with t1 as
(
select dt = @dt-day(@dt)+number
from master..spt_values a
where type = 'P' and @dt-day(@dt)+number <= dateadd(m,1,@dt)-day(@dt) and number>0
)
,t2 as
(
select wk = substring(datename(weekday,dt),3,1), ww = datepart(week,dt),dd = day(dt) from t1
)
select * from t2 pivot (max(dd) for wk in ([日],[一],[二],[三],[四],[五],[六])) b
http://topic.csdn.net/u/20101215/15/428F8D05-456E-4B21-A294-FE738481B59C.html