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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:36:41+00:00 2026-06-02T10:36:41+00:00

In a stored procedure I have an expression like select @some_val_in_percents = (@total_val /

  • 0

In a stored procedure I have an expression like

select @some_val_in_percents = (@total_val / 100) * @some_val

If I use the Round function like this:

select @some_val_in_percents = Round((@total_val / 100) * @some_val, 0)

will the result be rounded when the whole expression is calculated or will (@total_val / 100) be rounded and than multiplied by @some_val?

  • 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-02T10:36:42+00:00Added an answer on June 2, 2026 at 10:36 am

    You seem to be calculating the percent value wrongly. Here’s what I would expect it to be like:

    @some_val * 100 / @total_val
    

    As for the ROUND() function, it will act on the final result of the expression, not on the partial result. So, first the expression is evaluated completely, then ROUND() is applied to the result.

    Note also (in case you haven’t already known it) that if both operands of the division operator are integers, SQL Server will perform an integer division, i.e. the result of the division would be rounded down to the nearest integer even before ROUND() is applied. If you want to avoid that, make sure that at least one of the operands is not integer, e.g. like this:

    ROUND(@some_val * 100.0 / @total_val, 2)
    

    Note also the second argument (precision), which is required in Transact-SQL ROUND().

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

Sidebar

Related Questions

I have a stored procedure that does something like: IF @Param = '1' SELECT
Which command will executed first,If a stored procedure have individual multiple select commands;
Say I have a stored procedure consisting of several separate SELECT, INSERT, UPDATE and
I have a stored procedure with an IN OUT parameter declared like follows: create
I have a stored procedure with multiple insert/select statements. Let's say I'm using the
I have a stored procedure that logs some data, how can I call this
I have a SQL stored procedure of the form SELECT [fields] FROM [table] WHERE
please help me with writing this search sql stored procedure procedure may have different
I am in a situation where a stored procedure have to execute Query1: select
I have a rather complex SELECT statement in a stored procedure that I am

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.