我有一个仅用于计算的列。它显示0或正数,表示休假时间。在我们的时间表中,它作为负数输入,我将其转换为正数进行计算。我需要一个正值才能进入员工每个条目的NonWorkHrs列。它必须是用户ID中所有记录的相同值。
我尝试过使用case语句并在子查询中选择max
update DME
set NonWorkHrs =
(
select max(VacationHours)
from DME b
where useruid = b.useruid
and useruid in (1,2,3)
and NonWorkHrsHolder > 0
)
where useruid in (1,2,3)
我还尝试了一个案例陈述
update DME
set NonWorkHrs =
(case
when (VacationHours > 0)
then (VacationHours)
--no else statement is need. All rows should have the same value
end
)
where useruid in (1,2,3)
我在VacationHours列中将负的TimeEntered值转换为正值。 NonWorkHrs列用于计算以确定实际工作时间。
预期的结果是
Useruid UserFullName NonWorkHrs VacationHours TimeEntered
1 Jane Doe 8 8 -8
1 Jane Doe 8 0 10
1 Jane Doe 8 0 12
2 John Doe 18 18 -18
2 John Doe 18 0 23
3 Bob Builder 16 16 -16
3 Bob Builder 16 0 40
实际结果是
Useruid UserFullName NonWorkHrs VacationHours TimeEntered
1 Jane Doe 18 8 -8
1 Jane Doe 18 0 10
1 Jane Doe 18 0 12
2 John Doe 18 18 -18
2 John Doe 18 0 23
3 Bob Builder 18 16 -16
3 Bob Builder 18 0 40