Solved

T-SQL and Rounding

Posted on 2010-09-14
1
308 Views
Last Modified: 2012-06-21
I have the following t-sql...

SUM(DATEDIFF(MINUTE, CONVERT(datetime, tblProduction.startDate, 101) + ' ' + CONVERT(datetime, tblstarttime.time, 108), CONVERT(datetime, tblProduction.endDate, 101) + ' ' +
CONVERT(datetime, tblendtime.time, 108)) / 60) AS totalhours

It calculates the correct # of minutes, but when I /60 to get the hours, it rounds down.

How should I update this so when 30 minutes is calculated, I get 0.5 hours etc.

0
Comment
Question by:Jedidia
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 33672087
try this:

SUM(cast( DATEDIFF(MINUTE, CONVERT(datetime, tblProduction.startDate, 101) + ' ' + CONVERT(datetime, tblstarttime.time, 108), CONVERT(datetime, tblProduction.endDate, 101) + ' ' +
CONVERT(datetime, tblendtime.time, 108)) as decimal(20,4)) / 60.0) AS totalhours

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now