Alex Rivera | Logout

SQL - convert int to double

Asked 2012-05-18T12:51:26.367
12

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

Edit
Report

1 Answer

6

The easiest way to convert to double is multiplying by 1.0 like this:

   1.0 * (sum(CAST(StaffAttendance.FirstHalfStatus as Integer) + 
         CAST(StaffAttendance.SecondHalfStatus as integer)))/2 as TotalLeave
answered 2012-05-18T12:52:52.463

Your Answer