October 7, 2013 at 12:11 pm
Hello,
I need to convert the following calculation. The 2 and 13 are sums from other columns that I need to divide. Not sure why this isn't working, but here is what I have to do...
This should be the end result... 2/13 = 15.385%
However, I keep getting 2/13 = 0.1538461
Any help would be greatly appreciated!
October 7, 2013 at 12:19 pm
From some point of view, 0.1538461 is almost equal to 15.385%
What's your question? What do you need? Couldn't you do it on the front-end?
October 7, 2013 at 12:24 pm
I agree that the front end is the best place for display values. If you absolutely must do this in t-sql you will have to multiply your division result and then round and finally cast as the desired datatype.
Something like this.
select cast(round((2/13.0) * 100, 3) as numeric(5,3))
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 7, 2013 at 12:25 pm
People are complaining that they want to see the number as 15.385. I am in the process of setting up a report server so that will be later. I need to know how to convert this because using float, numeric(6,3), and decimal(13,3) are not working. Am I missing something?
Thanks very much for your quick response.
October 7, 2013 at 12:29 pm
DaveDB (10/7/2013)
People are complaining that they want to see the number as 15.385. I am in the process of setting up a report server so that will be later. I need to know how to convert this because using float, numeric(6,3), and decimal(13,3) are not working. Am I missing something?Thanks very much for your quick response.
If people are viewing the data that is the best location to do any formatting instead of formatting in sql.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 7, 2013 at 12:34 pm
I am going to do this conversion on SSRS when I get authorization to complete this install. Thanks for your help all!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply