Solved

T-SQL and Rounding

Posted on 2010-09-14
1
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

751 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