sqlserver2008 数据库 怎么实现传两个日期和星期几 查询出两日期之间星期对应的日期和星期几?
例如:传'2012-04-01' '2012-04-30' '星期日' 返回
2012-04-01 星期日
2012-04-08 星期日
2012-04-15 星期日
2012-04-22 星期日
2012-04-29 星期日
------解决方案--------------------
- SQL code
goif object_id('test')is not nulldrop table testgocreate table test([date] date)goinsert testselect '2012-04-01' union allselect '2012-04-02' union allselect '2012-04-03' union allselect '2012-04-04' union allselect '2012-04-05' union allselect '2012-04-06' union allselect '2012-04-07' union allselect '2012-04-08' union allselect '2012-04-09' union allselect '2012-04-10' union allselect '2012-04-11' union allselect '2012-04-12' union allselect '2012-04-13' union allselect '2012-04-14' union allselect '2012-04-15' union allselect '2012-04-16' union allselect '2012-04-17' union allselect '2012-04-18' union allselect '2012-04-19' union allselect '2012-04-20' union allselect '2012-04-21' union allselect '2012-04-22' union allselect '2012-04-23' union allselect '2012-04-24' union allselect '2012-04-25' union allselect '2012-04-26' union allselect '2012-04-27' union allselect '2012-04-28' union allselect '2012-04-29' union allselect '2012-04-30'select * from (select [date] 日期, case DATEPART(W,[date])-1 when 1 then '星期一' when 2 then '星期二' when 3 then '星期三' when 4 then '星期四' when 5 then '星期五' when 6 then '星期六' else '星期日' end as 星期from test)a where (日期 between '2012-04-01' and '2012-04-30')and 星期='星期日'/*日期 星期2012-04-01 星期日2012-04-08 星期日2012-04-15 星期日2012-04-22 星期日2012-04-29 星期日*/