Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:05:00+00:00 2026-06-12T02:05:00+00:00

I have an SQL Server 2008 table that can be illustrated as such: CREATE

  • 0

I have an SQL Server 2008 table that can be illustrated as such:

CREATE TABLE tbl (dtIn DATETIME2, dtOut DATETIME2)
INSERT tbl VALUES
('9/12/2012 3:21:22 AM', '9/12/2012 3:32:15 AM'),
('9/12/2012 3:58:52 AM', '9/12/2012 4:00:47 AM'),
('9/12/2012 4:02:00 AM', '9/12/2012 4:03:26 AM'),
('9/12/2012 4:04:34 AM', '9/12/2012 4:17:03 AM'),
('9/12/2012 4:22:37 AM', '9/12/2012 4:24:18 AM'),
('9/12/2012 5:35:27 AM', '9/12/2012 5:36:26 AM'),
('9/12/2012 5:37:00 AM', '9/12/2012 5:38:08 AM'),
('9/12/2012 5:38:36 AM', '9/12/2012 5:39:40 AM'),
('9/12/2012 5:44:22 AM', '9/12/2012 9:40:21 PM'),
('9/12/2012 9:41:28 PM', '9/12/2012 9:44:19 PM'),
('9/12/2012 10:25:40 PM', '9/12/2012 10:30:25 PM'),
('9/12/2012 10:30:40 PM', '9/12/2012 10:34:06 PM'),
('9/12/2012 10:37:53 PM', '9/12/2012 10:40:12 PM'),
('9/12/2012 10:40:17 PM', '9/12/2012 11:59:59 PM')   --and so on

I then need to execute a query like this (to calculate duration in minutes):

WITH ctx AS(
  SELECT datediff(minute, dtIn, dtOut) AS d FROM tbl
  )
SELECT SUM(d) FROM ctx

The issue with the query above is that I lose precision. For instance, this query for the table above will be 1 second off, which will get worse for more values to a point that I actually lose tens of minutes for a large dataset.

I was thinking to replace it with one of two alternatives, but I’m not sure which one is more efficient to use?

One with division:

WITH ctx AS(
  SELECT datediff(second, dtIn, dtOut) / 60.0 AS d FROM tbl
  )
SELECT SUM(d) FROM ctx

Or two with the cast (to prevent int overrun that goes as far as 68 years):

WITH ctx AS(
  SELECT datediff(second, dtIn, dtOut) AS d FROM tbl
  )
SELECT SUM(CAST(d AS BIGINT)) FROM ctx
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:05:02+00:00Added an answer on June 12, 2026 at 2:05 am

    Between your two queries, there really isn’t much difference. It can be said that integer maths is marginally faster than floating point, so you could prefer the latter if reporting by SECONDS is acceptable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains my ads that can be searched in sql-server-2008.
I have an SQL Server 2008 database with a table that has a column
I use SQL Server 2008 R2 and have a table that I want no
I'm using SQL Server 2008 and I have a table that has a 'Status'
I have a SQL Server 2008 R2 table with nvarchar(4000) field. Data that stores
I have a SQL Server 2008 database with a table that contains a FILESTREAM
I'm using SQL Server 2008. I have a database table that looks like this
I have a SQL Server 2008-R2 database that has a table that is storing
System is: SQL Server 2008-R2 I have a table that one of its column
In sql server 2008, I have a table that has the columns [a],[b],[c],[sort] and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.