Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scaled-down SQL


Scaled-down SQL

Author
Message
pksutha
pksutha
SSC Rookie
SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)

Group: General Forum Members
Points: 49 Visits: 58
My answer is like this
first part which is i 've answered:

Declare @value1 decimal(20,10),@value2 decimal(20,3)

SET @value1 = 1234567890.123456789
SET @value2 = 0.1

SELECT @value1 * @value2

Second part is screened answer:

DECLARE @value1 DECIMAL(20,10), @value2 DECIMAL(30,13)
SET @value1 = 1234567890.123456789
SET @value2 = 0.1

SELECT @value1 * @value2


Ans:
The screened answer is u 've declared value2 decimal(30,13)... why u need like that?
my answer is Declare @value1 decimal(20,10),@value2 decimal(20,3)...... this is enough in SQL server 2005
Duncan Pryde
Duncan Pryde
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3396 Visits: 1552
pksutha (3/22/2011)
My answer is like this
first part which is i 've answered:

Declare @value1 decimal(20,10),@value2 decimal(20,3)

SET @value1 = 1234567890.123456789
SET @value2 = 0.1

SELECT @value1 * @value2

Second part is screened answer:

DECLARE @value1 DECIMAL(20,10), @value2 DECIMAL(30,13)
SET @value1 = 1234567890.123456789
SET @value2 = 0.1

SELECT @value1 * @value2


Ans:
The screened answer is u 've declared value2 decimal(30,13)... why u need like that?
my answer is Declare @value1 decimal(20,10),@value2 decimal(20,3)...... this is enough in SQL server 2005


That's kind of the "moral" of the question. Never use a "bigger" decimal/numeric than you actually need.
michael.kaufmann
michael.kaufmann
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1293 Visits: 1082
Duncan Pryde (3/21/2011)
michael.kaufmann (3/21/2011)
tilew-948340 (3/20/2011)
[...]


[...]


Excellent explanation. Couldn't have put it better myself.


Thank you very much for your kind words of appreciation, Duncan.
Thanks again for your question and great explanation.

Regards,
Michael
Toreador
Toreador
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2412 Visits: 8061
Duncan Pryde (3/22/2011)
That's kind of the "moral" of the question. Never use a "bigger" decimal/numeric than you actually need.


The moral I've drawn is that maybe Floats aren't as bad as we thought...
rlswisher
rlswisher
SSC-Enthusiastic
SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)

Group: General Forum Members
Points: 134 Visits: 104
Declare @value1 numeric(38,10)
Declare @value2 numeric(1,1)
SET @value1 = 1234567890.123456789
SET @value2 = 0.1
SELECT @value1
SELECT @value2

SELECT @value1 * @value2
= "123456789.012345679"
Duncan Pryde
Duncan Pryde
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3396 Visits: 1552
rlswisher (3/22/2011)
Declare @value1 numeric(38,10)
Declare @value2 numeric(1,1)
SET @value1 = 1234567890.123456789
SET @value2 = 0.1
SELECT @value1
SELECT @value2

SELECT @value1 * @value2
= "123456789.012345679"


As expected.

Result precision is 38+1+1 = 40, scale is 10+1 = 11. Max allowed precision is 38, so precision and scale are reduced by 2, giving a final result precision and scale of 38,9 - which is why the result is rounded as you can see.
Duncan Pryde
Duncan Pryde
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3396 Visits: 1552
Toreador (3/22/2011)
Duncan Pryde (3/22/2011)
That's kind of the "moral" of the question. Never use a "bigger" decimal/numeric than you actually need.


The moral I've drawn is that maybe Floats aren't as bad as we thought...


Until you want to do something like this

Hehe
Gopi S
Gopi S
SSC-Enthusiastic
SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)

Group: General Forum Members
Points: 183 Visits: 325
Excellent question and nice explanation..
Learned something new that Precision and Scale varies for the resulting value
based on (+, -, / , *, [UNION | EXCEPT | INTERSECT] , % ) .

Thanks for posting this...
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21071 Visits: 18259
great qeustion



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

SanDroid
SanDroid
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1410 Visits: 1046
Great question. You would not believe how long and how often programers get this wrong.
There is even a list that is maintained of ROM chips that do weight conversions incorrectly becuase Dec(6,2) is used instead of Dec(13,5)

I even had to "show the math" on this exact thing a year ago when I had to explain why the weight conversion code used to change Pound to Kilos and vice versa was wrong in every appliation where I work.

Not understanding this math is why so many ships have a problem balancing thier loads.
Sometimes the cargo is weighed in pounds and the balast program uses Kilos.
Then someone uses a cheap hand calculator to convert the 100,000 tons in pounds to Kilos and the weghts off by at least 1,000 tons.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search