SQL - convert int to double

sql-server-2008

Solution

use `/2.0` instead to force decimal type

Edit:

To remove the trailing zeros cast to `float`. And I think you placed a `)` wrong. Try:

select cast(
           sum(
                 (
                   CAST(StaffAttendance.FirstHalfStatus as Integer) + 
                   CAST(StaffAttendance.SecondHalfStatus as integer)
                 ) 
                 / 2.0
           ) as float
       ) as TotalLeave
from your_table

Problem

I have two `bit` type columns in my sql table, and the values in it are like, ``` FirstHalfLeave SecondHalfLeave ------------ ------------- 0 1 1 1 ``` I need to sum these two fields to make it leave for a single day and I need to dislay the exact result`(3/2=1.5)` I just converted these `bit` to `integer` like ``` sum(CAST(StaffAttendance.FirstHalfStatus as Integer) + CAST(StaffAttendance.SecondHalfStatus as integer))/2 as TotalLeave ``` it showing the result as `1` not `1.5`, for this I think I need to cast it to double or to float, I dunno how to do this, can anyone help me here, thanks in advance

Original source