Sql Server 查询一段日期内的全部礼拜天
2017-07-23 14:01 tlnshuju 阅读(402) 评论(0) 编辑 收藏 举报/* 查询一段日期内的全部礼拜天 @startdate 開始日期 @enddate 结束日期 */ declare @startDate datetime declare @endDate datetime declare @week varchar(20) set @startDate = '20150101' set @endDate = '20151231' while @startDate <= @endDate begin set @week = DATENAME(weekday, @startDate); if (@week = '星期六' or @week = '星期日') begin select DATENAME(YEAR, @startDate) as "year", @startDate as "day" end set @startDate = @startDate + 1; end