Created
March 4, 2014 09:58
-
-
Save MilenPavlov/9343529 to your computer and use it in GitHub Desktop.
find intersection between two dates:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT EHS.EmployeeID, MAX(CASE WHEN FromDate >= @DateFrom THEN FromDate ELSE @DateFrom END) AS Starts, | |
MAX(CASE WHEN ToDate <= @DateTo THEN ToDate ELSE @DateTo END) AS Ends, E.Salaried, ISNULL(E.Salary, 0) as Salary | |
FROM EmployeeHolidaySickness EHS | |
LEFT OUTER JOIN Employees E ON EHS.EmployeeID = E.EmployeeID | |
WHERE (RecordType = 'H') AND (FromDate <= @DateTo AND ToDate >= @DateFrom) | |
GROUP BY EHS.EmployeeID, E.Salaried, ISNULL(E.Salary, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment