I have a column that is used for calculations only. It displays either a 0 or a positive number which represents vacation time. In our Time table it is entered as a negative number and I convert it to a positive number for calculations. I need that positive value to go into the NonWorkHrs column for each entry by an employee. It needs to be the same value for all records within a user ID.
I have tried using case statements and select max within a sub-query
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)
I also tried a case statement
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)
I convert the negative TimeEntered values to positive values in the VacationHours column. The NonWorkHrs column is used to in calculations to determine the actual work hours.
The expected result is
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
The actual result is
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