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 8837765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:48:39+00:00 2026-06-14T09:48:39+00:00

I’m working on SQLServer 2008 with the following table: id user program seconds ————————————

  • 0

I’m working on SQLServer 2008 with the following table:

id      user      program   seconds
------------------------------------
9999  'user01'    'pr01'       5

Column ‘seconds’ is defined as a decimal(14,0) and the only row in the table is the one shown.

So I try some queries:

Q1:

select seconds*0.95 from myTable
union all
select seconds from myTable

It gives the result I expect:

4.75
5.00

Q2:

select sum(seconds)*0.95 from myTable
union all
select sum(seconds) from myTable

I was expecting the same result as in Q1 but the result I get is:

5
5

Q3:

select sum(seconds)*0.95 from myTable
union all
select sum(seconds)*1.00 from myTable

In this case I get the results I expect:

4.75
5.00

So, I would like to know why Q2 is not getting the expected results. I have tried the same example with ‘seconds’ being a decimal(2,0) and works fine so I guess it has something to do with the size of the decimal, but in that case I cannot figure out why Q1 and Q3 work while Q2 does not.

  • 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-14T09:48:41+00:00Added an answer on June 14, 2026 at 9:48 am

    The result of sum(seconds) is numeric(38,0) which makes sense as you could be summing any number of numeric(14,0) rows and this avoids overflowing a smaller type.

    Multiplying a numeric(38,0) by 0.95 (numeric(2,2)) in the top part gives a result of numeric(38,2) as per the explanation here.

    But the bottom part of the union is numeric(38,0) so the result as a whole is cast to numeric(38,0) which again makes sense as numeric(38,2) can always cast to numeric(38,0) without error (albeit with a loss of digits after the decimal) but casting the other way won’t work at all for very large numbers.

    You can cast the bottom part explicitly to numeric(38,2) to avoid this.

    SELECT sum(seconds) * 0.95 AS S
    FROM   myTable
    UNION ALL
    SELECT CAST(sum(seconds) AS NUMERIC(38, 2))
    FROM   myTable 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
string formIdList = 8256, 8258, 8362, 8120, 8270, 8271, 8272, 8273, 8257, 8279, 8212,
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.