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

sql:计算工作日
我的业务逻辑是:
客户投诉表A: complaintdate;
日历表B:calendardate (有节假日设定),status :1 工作日;2:周末;3:国定假日;


我想查询表A 中的complaintdate的日期与当前日期相比,超过5个工作日的数据查出来;怎么写这样的sql?

------解决方案--------------------
select a.complaintdate,b.status
from A a,B b
having DATEDIFF(DD,a.complaintdate,GETDATE())>5
------解决方案--------------------
SQL code

SELECT  * FROM A WHERE (having DATEDIFF(DD,complaintdate,GETDATE())-
SELECT COUNT(1) FROM B WHERE status IN(2,3) AND calendardate BETWEEN A.complaintdate  AND GETDATE())>5