Solved

decimel help

Posted on 2014-10-22
13
170 Views
Last Modified: 2014-10-25
Hello All,

I have a table where a column is gets updated by the division of a column from another table by any denominator value between 3 and 9. So it could be metric column / 3  or metriColumn/4 , etc.

Now in terms of the maximum of decimals for highest accuracy – s – what should be used? Wen creating that table to store the division result column – I am using –
CREATE TABLE [dbo].[myTable](
            [divisionResults] [decimal](18, 4) NULL
) ON [PRIMARY]

 I want to use storage type that allows me the maximum decimal places after zero but also doesn’t compromise the query efficiency or speed or that I am “overkilling” it
0
Comment
Question by:Rayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40398670
You can see the precision for decimal data type here and as far as I know the precision doesn't impact the query performance.
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40399656
One additional thing to rember is when you do math in sql with an int and a decimal, depending on the specific order of the numbers (decimal/int , int/decimal) you can get the result as an int when you want a decimal.
http://www.experts-exchange.com/Database/MS-SQL-Server/Q_24432624.html

I prefer to explicitly cast my int as a decimal but there are lots of ways.
Decimal / cast (int as decimal(18,4)
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40399717
depending on the specific order of the numbers (decimal/int , int/decimal) you can get the result as an int when you want a decimal.
That's not true. In both case the result will be always a decimal.
Only if the operation is int/int that the result will be int.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40400122
whoops, that's right. I've just gotten in the habit of casting everything to avoid odd issues.
http://improve.dk/tricky-sql-server-decimal-math/
0
 

Author Comment

by:Rayne
ID: 40400557
[myResults] [decimal](18, 4) NULL
so whats the max number of decimel that i can use? instead of 4 like up till 12 or more?
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40400567
0
 

Author Comment

by:Rayne
ID: 40400656
please suggest a valid one - this is leading to arithmetic overflow
0
 

Author Comment

by:Rayne
ID: 40400659
all eexperts - please suggest whats your best practise of using which one decimel ? i dont want my program to crash
0
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 50 total points
ID: 40400742
in your example (18,4) that means 18 total digits, 4 to the right of the decimal point. Unless you care about more digits to the right of the decimal point, that should be fine for numbers up to 99 trillion (99,999,999,999,999.9999)
0
 
LVL 49

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 50 total points
ID: 40401165
all eexperts - please suggest whats your best practise of using which one decimel ? i dont want my program to crash
There's no best practice but client/business demands. What's the precision that they need? You just need this answer to set the best data type.
0
 
LVL 16

Accepted Solution

by:
DcpKing earned 400 total points
ID: 40401882
As Aaron and Vitor say, you select your total number of digits and your number of decimal places within that, For example, if you're working with something like national expenditures then 18,4 might be good. OTOH, for chemical analyses something like 18,12 might be more appropriate.

As others have noted, use a decimal value as your denominator, if for no other reason than to make everything clear to subsequent readers of your code. If you are working with large amounts of data then every calculation will include an implicit conversion if you leave it as an integer. While this probably won't be as expensive as dividing by '4' (as a varchar or char) it will still incur some extra overhead.

hth

Mike
0
 

Author Closing Comment

by:Rayne
ID: 40403538
Thank you Sire Mike and the other Gurus, thank you
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 40404442
"Sire Mike" !! LOL!!!

I appreciate the thought.  --  Mike
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question