sqlserver如何根据给出的时间段获取其中每个星期一
比如startTime 2013-01-01 01:00:00 endTime 2013-04-26 01:00:00 另外一个参数是 @int (@int = 1代表星期日,2代表星期一,依次后推)
那么如何检索到这个时间段内的每个@int 对应的日期呢
select * from table_1 where datepart(weekday, coltime)=@int
DECLARE @startTime DATETIME ='2013-01-01 01:00:00'declare @endTime DATETIME ='2013-04-26 01:00:00'DECLARE @int INT = 1 SET DATEFIRST 7 SELECT * FROM ( SELECT DATEADD(dd, number, @starttime) AS dd FROM master..spt_values M WHERE type = 'P' )T WHERE dd BETWEEN @starttime AND @endtime AND DATEPART(dw,dd) = @int
SELECT id FROM A WHERE updatetime BETWEEN @starttime AND @endtime AND DATEPART(hh, updatetime) = 7 AND DATEPART(mi, updatetime) BETWEEN 0 AND 30 AND datapart(dw, updatetime) = @int
|