Frage

This is one line from my stored procedure. My table field hoursworked is storing minutes. How to store it by dividing it to 60.

(select 
    SUM(ISNULL(hoursworked,0)) 
 from 
    UserTime 
 where 
    userid = @employeeid 
    and convert(varchar(100),checkin,106) = convert(varchar(100),@Startdate,106) 
    and loginstatus= 'Out') 


hoursworked as int

how can I implement this

SUM(ISNULL(hoursworked/60,0))
War es hilfreich?

Lösung

What you probably got is 0. You should do the sum() first:

coalesce(sum(hoursworked)/60, 0)

The problem is that SQL Server does integer division, so any value less than 60 (and greater than or equal to 0) will result in 0. You might really want:

coalesce(sum(hoursworked)/60.0, 0)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top