2015-01-05 2 views
0

새해 복 많이 받으세요. DateDiff를 사용하여 Excel Networkdays로 작업

그래서 나는 그것을 비 작업 계산에 일 (주말 및 공휴일 포함되어 DATEDIFF 함수를 사용하면 특정 테이블 (targetdate)

에 오늘 날짜 (GETDATE())과 목표 일의 차이를 해결하려고 노력하고있다). 타사 공급 업체에서 제공 한 날짜 달력 표가 주말을 알려주지 만 은행 휴일은 알려주지 않습니다.

다행스럽게도 데이터베이스에는 - ih_non_work_days라는 다른 테이블이 있습니다.

날짜의 형식은 예를 들어 그 테이블에 "2014-12-25 00:00:00.000"입니다.

어떻게 "targetdate" and today's date을 사용하여 차이를 계산합니까? ih_non_work_days 데이터베이스에있는 날짜는 제외합니까?

그래서 지금 내 기본 스크립트는 모양을 위해 -

SELECT com.comm_reference AS 'Referance' 
    ,com.current_task_target_date AS 'TargetDate' 
      , DATEDIFF(D,com.current_task_target_date,GETDATE()) AS 'Incorrect Date Calculation' 
FROM [dbo].[em_communication] as com 

답변

0
SELECT C.comm_reference AS Referance ,C.current_task_target_date AS TargetDate ,DATEDIFF(d, C.current_task_target_date,CURRENT_TIMESTAMP) - NoWorkDays AS 'Days Past Target Date' FROM [dbo].[em_communication] C CROSS APPLY (SELECT COUNT(*) AS NoWorkDays FROM [dbo].[ih_non_work_days] D WHERE D.date_off BETWEEN C.current_task_target_date AND CURRENT_TIMESTAMP) N; 
관련 문제