我需要添加的是当员工职称X在SAME分支内切换到不同的职位(Y或Z)时,修改他们在该新职称(Y或Z)中所用季度的总FTE )。
所以逻辑是:
IF [Position Start Date] is between [Q2 start date] AND [Q2 end date]
and [Employee Title] of [Employee ID] was X and is now Y
THEN [Total FTE calculated] = (((([Position Start Date] - [Quarter Start Date])/[Days in Quarter]) * [Total FTE]) + ((([Quarter End Date] - [Position Start Date])/[Days in Quarter]) * [Total FTE]) * 0.5)
AND IF [Position Start Date] is between [Q2 start date] AND [Q2 end date]
AND [Employee Title] of [Employee ID] was X and is now Z
THEN [Total FTE calculated] = ([Position Start Date] - [Quarter Start Date])/[Days in Quarter]) * [Total FTE])
ELSE [Total FTE Calculated] = [Total FTE] * 1
END
正如您所看到的,我缺少一些SQL运算符的知识来正确执行此操作。您将提供的任何帮助将不胜感激! 拜托,谢谢!
答案 0 :(得分:2)
粗略的草图,日期算术在不同的DBMS供应商之间有很大不同,所以我使用了你的表达式。我已经将变量:new_emplyee_title用于新标题。
update Employees
set [Total FTE calculated] = case when :new_emplyee_title = Y
then [ expression for Y ]
else [ expression for Z ]
end
where [Position Start Date] between [Q2 start date] AND [Q2 end date]
and [Employee Title] = X
and :new_emplyee_title in (Y,Z);
如果您使用DBMS支持触发器,这就像在更新触发器中一样。