Solved

T-SQL and Rounding

Posted on 2010-09-14
1
306 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now