日期:2014-05-18  浏览次数:20416 次

Sql 难题 我是菜鸟谁来帮我
我想查询一个时间段内的日期的内容,好比说2010年1月20日~~~~2012年3月1日 每日的5号的数据

还要判断如果五号是周六或者周日的话, 按周五的数据 得出来这个时间段的内容 该怎么做呀




------解决方案--------------------
SQL code

set datefirst 1

select *
from tb
where date between '2010-01-20' and '2012-03-01'
    and day(date) = (case when datepart(weekday,date) in (6,7) and day(date) = 5
                          then 10-datepart(weekday,date) else 5 end)

-- try