日期:2014-05-17 浏览次数:20525 次
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
/*
2013-01-06 01:00:00.000
2013-01-13 01:00:00.000
2013-01-20 01:00:00.000
2013-01-27 01:00:00.000
2013-02-03 01:00:00.000
2013-02-10 01:00:00.000
2013-02-17 01:00:00.000
2013-02-24 01:00:00.000
2013-03-03 01:00:00.000
2013-03-10 01:00:00.000
2013-03-17 01:00:00.000
2013-03-24 01:00:00.000
2013-03-31 01:00:00.000
2013-04-07 01:00:00.000
2013-04-14 01:00:00.000
2013-04-21 01:00:00.000*/