1

計算のみに使用される列があります。休暇時間を表す 0 または正の数値が表示されます。時間テーブルでは、負の数として入力され、計算のために正の数に変換します。従業員による各エントリの NonWorkHrs 列に正の値が入る必要があります。ユーザー ID 内のすべてのレコードで同じ値である必要があります。

サブクエリ内で case ステートメントと select 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
4

3 に答える 3