[MSSQL]根据年得到所有星期日的日期
2012-02-16 12:39
302 查看
go --创建函数 create function GetWeekDays(@year int) returns @t table (星期天varchar(20)) as begin 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 return end --测试示例 select * from dbo.GetWeekDays(2011) --运行结果 /* 星期天 -------------------- 2011-01-02 2011-01-09 2011-01-16 2011-01-23 2011-01-30 2011-02-06 2011-02-13 2011-02-20 2011-02-27 2011-03-06 2011-03-13 2011-03-20 2011-03-27 2011-04-03 2011-04-10 2011-04-17 2011-04-24 2011-05-01 2011-05-08 2011-05-15 2011-05-22 2011-05-29 2011-06-05 2011-06-12 2011-06-19 2011-06-26 2011-07-03 2011-07-10 2011-07-17 2011-07-24 2011-07-31 2011-08-07 2011-08-14 2011-08-21 2011-08-28 2011-09-04 2011-09-11 2011-09-18 2011-09-25 2011-10-02 2011-10-09 2011-10-16 2011-10-23 2011-10-30 2011-11-06 2011-11-13 2011-11-20 2011-11-27 2011-12-04 2011-12-11 2011-12-18 2011-12-25 (52 row(s) affected) */
相关文章推荐
- [MSSQL]根据年得到所有星期日的日期
- 根据年得到所有星期日的日期
- 【叶子函数分享四十八】根据年得到所有星期日的日期
- 【叶子函数分享四十八】根据年得到所有星期日的日期
- 根据年得到所有星期日的日期
- 根据某个日期得到该月的所有日期
- java方法,返回两个日期内的所有date集合,根据开始时间、结束时间得到两个时间段内所有的日期
- java 根据开始和结束日期得到之间所有日期集合
- 根据年月(如2013-05)得到该月的所有日期及对应日期是周几
- java方法,返回两个日期内的所有date集合,根据开始时间、结束时间得到两个时间段内所有的日期
- java 根据开始和结束日期得到之间所有日期集合
- 【java】根据开始时间、结束时间得到两个时间段内所有的日期
- js根据开始日期和结束日期得到中间的所有日期
- js得到连两个时间段之间所有的年-月 获取当前日期 格式化日期 根据指定日期得到该日期该月份的最后一天
- [MSSQL]Sql Server根据表名获取表的所有列及属性
- 根据日期(年月日)得到星期几的方法
- C#中如何根据身份证号码得到出生日期和性别
- java 根据给定的日期得到给定日期的前一天的日期
- 根据日期得到当月第一天和最后一天
- 根据根节点得到所有的叶子节点 CONNECT BY