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 

look image pls

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -