473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Rounding up to the nearest minute

347 100+
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
Jan 12 '11 #1
9 3071
Rabbit
12,516 Expert Mod 8TB
You mean like the ROUND function?
Jan 12 '11 #2
dougancil
347 100+
I guess that would be it. Where would I put that in my query?
Jan 12 '11 #3
Rabbit
12,516 Expert Mod 8TB
You put it around the number you want to round.
Expand|Select|Wrap|Line Numbers
  1. ROUND(cast (sum (ontime) as decimal (10,2)), 2)
Jan 12 '11 #4
dougancil
347 100+
I'm sorry I was looking at the wrong query. This is the one I need to have the ROUND function in:

SELECT DISTINCT [ScratchPad5].EmployeeNumber, Sum([ScratchPad5].sumhours),
SUM(Case when [sumhours]>40
THEN [sumhours]-40
ElSE 0
END) AS TotalOT,
SUM(Case when [sumhours]>40
THEN 40
ELSE [sumhours]
End) AS TotalRegHours

From Scratchpad5
Group By
[Scratchpad5].Employeenumber,
Sumhours

Where would it go here?

Thanks
Jan 12 '11 #5
Rabbit
12,516 Expert Mod 8TB
You would do the same thing I did in my earlier example. Put it around the number you want to round.

Expand|Select|Wrap|Line Numbers
  1. ROUND(expression, # of decimal digits)
Jan 12 '11 #6
dougancil
347 100+
So something like this?

SELECT DISTINCT [ScratchPad5].EmployeeNumber, Sum([ScratchPad5].sumhours),
Round(SUM(Case when [sumhours]>40,2)
THEN [sumhours]-40
ElSE 0
END) AS TotalOT,
SUM(Case when [sumhours]>40
THEN 40
ELSE [sumhours]
End) AS TotalRegHours

From Scratchpad5
Group By
[Scratchpad5].Employeenumber,
Sumhours
Jan 12 '11 #7
Rabbit
12,516 Expert Mod 8TB
Not quite, your case and sum statements extend beyond the first line. You'll want to bring the end of the round statement to the end of the sum statement.
Jan 12 '11 #8
dougancil
347 100+
Ok, I'm obviously missing where this goes, I've tried a few places and can't seem to place it correctly.

Should it go inside the SUM statement or outside?
Jan 12 '11 #9
Rabbit
12,516 Expert Mod 8TB
Outside the SUM, your SUM extends multiple lines. Didn't you write the original SQL? If you wrote the SUM and CASE statements, you should know where they end.
Jan 12 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: b | last post by:
Hello all, we have a table that is part of our accounting package that stores decimals as such: 123.45678. However the reporting standards with the accounting system display that as 123.45 note...
8
by: Geoff Jones | last post by:
Hi Is there a way to round up or down time intervals. For example, suppose we have a variable storing the time 14:06, what is the easiest way to round it to the nearest minute? Thanks in...
6
by: Jeff Boes | last post by:
(asked last week on .questions, no response) Can anyone explain why this happens? (under 7.4.1) select '2004-05-27 09:00:00.500001-04' :: timestamp(0) ; timestamp ---------------------...
12
by: 6tc1 | last post by:
Hi all, I just discovered a rounding error that occurs in C#. I'm sure this is an old issue, but it is new to me and resulted in a fair amount of time trying to track down the issue. Basically...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
5
by: Marcus | last post by:
Hi, was wondering if anyone knows a good algo for rounding time to a desired interval. For instance, I have data set that is timestamped in second resolution and I need to modify that data to be...
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
2
by: JHNielson | last post by:
I have a coupe of queries where I use the Time() function. Later I need to match these records to each other. But I have a certain situation where the queries are run on different records at barely...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.