Declare @YMD Varchar(10)='2015-04-01'
;
With T
As
(
Select Dateadd(day,number,@YMD) As D
From Master.dbo.spt_values Where Type='P'
And number Between 0 And 31
)
Select
Isnull([1],'') As Sun,
Isnull([2],'') As Mon,
Isnull([3],'') As Tue,
Isnull([4],'') As Wed,
Isnull([5],'') As Thu,
Isnull([6],'') As Fri,
Isnull([7],'') As Sat
From
(
Select Convert(Varchar(2),day(D)) As Y,DATEPART(WEEKDAY,D) As X,
DATEPART(WEEK,D) As Z
From T
Where Month(D)=Month(@YMD)
) S
Pivot
(
Max(Y)
For
X in([1],[2],[3],[4],[5],[6],[7])
)P
SQL版月历
猜你喜欢
转载自blog.csdn.net/mxbing1984/article/details/82555515
今日推荐
周排行