问题描述
当前查询不会保留2011年开始使用EmpStatus ="A"的天数(DU).它只是在2012年获得新记录.有什么建议吗?
以DR FROM(
)选择Employee.EmpID,Trippin.EmpUID,Trippin.DU,Employee.FirstName,Employee.LastName,(84-DU)SELECT EmpUID,Sum(DaysUsed)作为DU FROM(
SELECT EmpUID,SUM(DateDiff(d,StartDate,StopDate))从dbo.EmpStatH中使用的天数EmpStatus =``A''AND StartDate不为空且StopDate为NULL并且DatePart(yy,StartDate)= DatePart(yy,GetDate ())GROUP BY EmpUID
UNION
选择EmpUID,SUM(DateDiff(d,(DATEADD(yy,DATEDIFF(yy,0,getdate()),0)),StopDate))从dbo.Used天开始使用.EmpStatH WHERE EmpStatus =``A''并且StartDate不是NULL AND StopDate不是NULL AND DatePart(yy,StartDate)< DatePart(yy,GetDate())和DatePart(yy,StopDate)= DatePart(yy,GetDate())GROUP BY EmpUID
UNION
SELECT EmpUID,SUM(DateDiff(d,StartDate,GetDate()))从dbo.EmpStatH开始使用的天数EmpStatus =``A''AND StartDate不为空且StopDate为NULL并且DatePart(yy,StartDate)= DatePart(yy) ,GetDate())GROUP BY EmpUID
)作为EmpUID的AS Jumpoff GROUP)作为Trippin的左联接JOIN员工在Trippin.EmpUID = Employee.EmpUID的位置DU> 70 AND DU< 86 AND Employee.TermDate是NULL DE BY DU DESC
Current query doesn''t carry over Days Used (DU) who started EmpStatus = ''A'' in 2011. It is only picking up new records in 2012. Any suggestions?
SELECT Employee.EmpID, Trippin.EmpUID, Trippin.DU, Employee.FirstName, Employee.LastName, (84-DU) as DR FROM (
SELECT EmpUID, Sum(DaysUsed) as DU FROM (
SELECT EmpUID, SUM(DateDiff(d,StartDate,StopDate)) AS DaysUsed FROM dbo.EmpStatH WHERE EmpStatus = ''A'' AND StartDate IS NOT NULL AND StopDate IS NULL AND DatePart(yy,StartDate) = DatePart(yy,GetDate()) GROUP BY EmpUID
UNION
SELECT EmpUID, SUM(DateDiff(d,(DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)),StopDate)) AS DaysUsed FROM dbo.EmpStatH WHERE EmpStatus = ''A'' AND StartDate IS NOT NULL AND StopDate IS NOT NULL AND DatePart(yy,StartDate) < DatePart(yy,GetDate()) AND DatePart(yy,StopDate) = DatePart(yy,GetDate()) GROUP BY EmpUID
UNION
SELECT EmpUID, SUM(DateDiff(d,StartDate,GetDate())) AS DaysUsed FROM dbo.EmpStatH WHERE EmpStatus = ''A'' AND StartDate IS NOT NULL AND StopDate IS NULL AND DatePart(yy,StartDate) = DatePart(yy,GetDate()) GROUP BY EmpUID
) AS Jumpoff GROUP BY EmpUID) AS Trippin LEFT JOIN Employee ON Trippin.EmpUID = Employee.EmpUID WHERE DU > 70 AND DU < 86 AND Employee.TermDate IS NULL ORDER BY DU DESC
推荐答案
这篇关于需要连续跨天的“已用天数"计数-FMLA到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!