查询列出两个日期间的所有星期

declare @startdate datetime,@enddate datetime
set @startdate='2009-08-30'
set @enddate='2011-09-15'
 
select DATENAME(year,dateadd(week,number,@startdate)) + 'W' + DATENAME(week,dateadd(week,number,@startdate))
from
    master..spt_values 
where 
    datediff(day,dateadd(week,number,@startdate), @enddate)>=0
    and number>=0 
    and type='p'

查询结果

2009W36
2009W37
...............
2011W37
2011W38


另有一篇详细讨论的文章

http://blog.csdn.net/tianlianchao1982/article/details/5585537

你可能感兴趣的:(查询列出两个日期间的所有星期)