根據年得到所有星期日的日期

來源:互聯網
上載者:User

標籤:top   convert   table   style   datetime   weight   tab   arch   nbsp   

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 join    ( select  top 365 b8.i+b7.i + b6.i + b5.i + b4.i +b3.i +b2.i + b1.i + b0.i x    from(select 0 i union all select 1) b0    cross join(select 0 i union all select 2) b1    cross join(select 0 i union all select 4) b2    cross join(select 0 i union all select 8) b3    cross join(select 0 i union all select 16) b4    cross join(select 0 i union all select 32) b5    cross join(select 0 i union all select 64) b6    cross join(select 0 i union all select 128) b7    cross join(select 0 i union all select 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-062011-03-132011-03-202011-03-272011-04-032011-04-102011-04-172011-04-242011-05-012011-05-082011-05-152011-05-222011-05-292011-06-052011-06-122011-06-192011-06-262011-07-032011-07-102011-07-172011-07-242011-07-312011-08-072011-08-142011-08-212011-08-282011-09-042011-09-112011-09-182011-09-252011-10-022011-10-092011-10-162011-10-232011-10-302011-11-062011-11-132011-11-202011-11-272011-12-042011-12-112011-12-182011-12-25 (52 row(s) affected)*/

 

根據年得到所有星期日的日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.