Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Rounding up to the nearest minute

Author  Topic 

dougancil
Posting Yak Master

217 Posts

Posted - 2011-01-12 : 10:35:42
I have the following query:

select name, employeenumber, dateadd(day,datediff(day,0,date),0) as dateonly,(cast (sum (ontime) as decimal (10,2))) as minutes into scratchpad2
from scratchpad1
where date between '10/3/2010' and '10/10/2010'
group by employeenumber, name ,dateadd(day,datediff(day,0,date),0)
order by employeenumber asc

that rounds to the nearest minute, but my data results look like this:

8245 36.965166 .000000 36.965166
8247 10.292000 .000000 10.292000
8295 29.162833 .000000 29.162833
8378 21.346000 .000000 21.346000
8389 13.414333 .000000 13.414333
8428 29.329666 .000000 29.329666
8433 16.928833 .000000 16.928833
8442 10.647500 .000000 10.647500
8451 13.567500 .000000 13.567500
8455 23.935166 .000000 23.935166

what I would like is to have the sums rounded to the nearest minute with only 2 decimal places instead of the 6 that I have. Can someone please assist?

So for example, this line

8245 36.965166 .000000 36.965166

would be

8245 36.97 .000000 36.97

Thank you

Doug

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-01-12 : 15:01:32
Use ROUND function?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

dougancil
Posting Yak Master

217 Posts

Posted - 2011-01-19 : 12:52:44
Peso,

Thats exactly what I did:

select name, employeenumber, dateadd(day,datediff(day,0,date),0) as dateonly,ROUND(cast (sum (ontime) as decimal (10,2)),2) as minutes into scratchpad2
from scratchpad1
where date between @payrollstartdate And @payrollenddate
group by employeenumber, name ,dateadd(day,datediff(day,0,date),0)
order by employeenumber asc
Go to Top of Page
   

- Advertisement -