February 22, 2010 at 12:02 am
Hi
Look at these SELECT statements.
1. SELECT CAST(1.67574 AS DECIMAL(38,10)) A, CAST(10000 AS DECIMAL(38,10)) B
2. SELECT CAST(1.67574 AS DECIMAL(38,10)) / CAST(10000 AS DECIMAL(38,10)) conv_factor
When first statement is run the result is
A B
1.675740000010000.0000000000
But, when the second one runs, the result is
conv_factor
0.000167
Both the numbers are converted into DECIMAL(38,10) before the division, but, why did this truncation occured?
February 22, 2010 at 5:50 am
Hi,
Try this,
SELECT CAST(CAST(1.67574 AS DECIMAL(38,10)) / CAST(10000 AS DECIMAL(38,10)) AS DECIMAL(38,10)) conv_factor
SQL server taking a default scale, you need to explicitly specify the precision and scale.
regards
Hari
February 22, 2010 at 7:49 am
Duplicate thread.
I posted a comprehensive answer here:
http://www.sqlservercentral.com/Forums/Topic870098-338-1.aspx
February 22, 2010 at 10:45 pm
Thanks paul, that was good one.
regards
Hari
February 22, 2010 at 10:53 pm
Hariprasad.M (2/22/2010)
Thanks paul, that was good one.
No worries, Hari - I enjoyed writing the reply. It would be cool if you would just post your questions in one forum from now on though 😉
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply