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
9 3071
You mean like the ROUND function?
I guess that would be it. Where would I put that in my query?
You put it around the number you want to round. - ROUND(cast (sum (ontime) as decimal (10,2)), 2)
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
You would do the same thing I did in my earlier example. Put it around the number you want to round. - ROUND(expression, # of decimal digits)
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
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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
---------------------...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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)
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
| |