sql server - sql. syntax select Perform Arithmetic Operations -
i want perform arithmetic operations in select syntac sql 10 minus 5 = 5 select not work.
select datediff(minute,on_duty, clock_in ) late, datediff(minute ,off_duty, clock_out ) early, late - jajalan kkpsurabaya
you cannot use result of function in same select because you cannot refer alias outside of select , order because of way query parsed. call same function multiple times:
select datediff(minute,on_duty, clock_in ) late, datediff(minute ,off_duty, clock_out ) early, datediff(minute,on_duty, clock_in )- datediff(minute ,off_duty, clock_out ) jajalan kkpsurabaya
or common-table-expreession:
with cte ( select datediff(minute,on_duty, clock_in ) late, datediff(minute ,off_duty, clock_out ) early, t.* kkpsurabaya t ) select late, early, late - jajalan cte
Comments
Post a Comment