Avatar of bfuchs
bfuchs
Flag for United States of America

asked on 

Adding an if condition to an existing calculated field.

Hi Experts,

I have a column in my view named Duration defined as following.
CASE WHEN Shift_From_Hour IS NULL OR Shift_To_Hour IS NULL THEN 0 WHEN Shift_From_Hour < 0 OR Shift_From_Hour > 24 OR Shift_From_Minute < 0 OR Shift_From_Minute > 59 THEN 0 WHEN Shift_To_Hour < 0 OR Shift_To_Hour > 24 OR Shift_To_Minute < 0 OR Shift_To_Minute > 59 THEN 0 WHEN Shift_From_Hour > Shift_To_Hour THEN ((24 - Shift_From_Hour) + Shift_To_Hour) * 60 + (Shift_To_Minute - Shift_From_Minute) ELSE (Shift_To_Hour - Shift_From_Hour) * 60 + (Shift_To_Minute - Shift_From_Minute) END

Open in new window


Now would like to add a new field to my view named Duration2 having the following logic.
Duration2: CInt(IIf([duration]=0,1440,[duration])/60)

Open in new window

(Code taken from Access query).
Meaning if the duration column is 0 it should return 1440/60, otherwise return the results of Duration column divided by 60.

Thanks
DatabasesMicrosoft SQL ServerSQL

Avatar of undefined
Last Comment
bfuchs

8/22/2022 - Mon