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

  • Home
  • SEARCH
  • 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 7605683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:13:44+00:00 2026-05-31T00:13:44+00:00

Im currently working on a sql database that carries out several calculations based on

  • 0

Im currently working on a sql database that carries out several calculations based on external data.

Basically I have a field called ‘Runhrs’ and i take the max and min values of a specific day or a range of days.

The calculation will sometimes return (for example) 26 hours but as we know its not possible to have more than 24 hors in a day. The Calculation is correct but the data itself seems to have the errors but nothing can be done about the datas errors.

Therefore how do i limit the max value? The SQL statement is as shown:

    SELECT MAX(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) - MIN(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) AS RUNHO, CONVERT(VARCHAR,TIME_STAMP,103) AS TIME_STAMP 
FROM HL_LOGS 
WHERE TIME_STAMP BETWEEN @BEGIN AND @END AND ID_LOCATION = @ID 
GROUP BY CONVERT(VARCHAR,TIME_STAMP,103), CONVERT(VARCHAR,TIME_STAMP,111) 
ORDER BY CONVERT(VARCHAR,TIME_STAMP,111)

Thanks in advance,
Neil.

  • 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-05-31T00:13:46+00:00Added an answer on May 31, 2026 at 12:13 am

    Try using a CASE clause:

    SELECT CASE when MAX(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) -
                     MIN(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) > 24
                then 24
                else MAX(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) -
                     MIN(CONVERT(FLOAT,ISNULL(Runhrs,Runho))) 
           END AS RUNHO,
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have an application that pulls data from a SQL database as well
I'm currently working with MS SQL 2005, and have a table that has 17
I have written a working T-SQL MERGE statement. The premise is that Database A
I am currently working on a VB.NET desktop application that uses .mdb (Access) database
I'm currently working on a wcf service that does some lookups in a database
I am currently working on a data management system that needs to calculate huge
I'm currently working my way through the Microsoft SQL Server 2008 - Database Development
I have a SQL Server 2005 database that I'm trying to access as a
I have a java application that sends text to a sql database on a
I'm currently working on a project that uses data access on different databases. Our

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.