문제

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))
도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top