工作中用到了這樣一段,所以就干脆記下來,下面只是一段sql語句,也可以改成函數這樣更方便,不過我覺得這樣也很好用了.
declare
@initday
varchar
(
10
)
declare @endday varchar ( 10 )
set @initday = ' 2008/01/01 '
set @endday = ' 2008/06/30 '
declare @i datetime
select @i = convert ( datetime , @initday )
while ( @i <= convert ( datetime , @endday ))
begin
insert into calendar(ymd,weekstr) values ( convert ( varchar ( 10 ), @i , 111 ), datename (weekday, @i ) )
set @i = dateadd ( day , 1 , @i )
end
declare @endday varchar ( 10 )
set @initday = ' 2008/01/01 '
set @endday = ' 2008/06/30 '
declare @i datetime
select @i = convert ( datetime , @initday )
while ( @i <= convert ( datetime , @endday ))
begin
insert into calendar(ymd,weekstr) values ( convert ( varchar ( 10 ), @i , 111 ), datename (weekday, @i ) )
set @i = dateadd ( day , 1 , @i )
end
添加進calendar表中的內容格式如下:
2008/01/01 星期二
2008/01/02 星期三
2008/01/03 星期四
.......