June 17, 2009 at 2:27 am
Hi!
My recommendation is to never use default values because of maintainability. What would happen if MS (I really hope they dont) changes the default value for decimal in this case? You will get a different result than expected. Thats one of the reasons I never rely on default values.
Håkan Winther
/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
June 17, 2009 at 6:29 am
I'm curious where it speaks about rounding in the linked article... I couldn't see it anywhere. It just says the default for the precision and the scale!
June 17, 2009 at 9:05 am
ta.bu.shi.da.yu (6/17/2009)
I'm curious where it speaks about rounding in the linked article... I couldn't see it anywhere. It just says the default for the precision and the scale!
True, you would have to click through links at the bottom of the article to get to this page that discusses rounding:
http://msdn.microsoft.com/en-us/library/ms191530.aspx#_decimal
June 18, 2009 at 5:33 am
June 18, 2009 at 5:56 am
ta.bu.shi.da.yu (6/18/2009)
Ah... but how would you get around that? Is there any way of disabling the rounding?
You could use SET NUMERIC_ROUNDABORT ON to get an error instead of a rounded value. Using this with the question's query gives an error message, for example
SET NUMERIC_ROUNDABORT ON
declare @d decimal
select @d = 3.564636
select @d
[font="Courier New"]Msg 8115, Level 16, State 7, Line 7
Arithmetic overflow error converting numeric to data type numeric.[/font]
June 18, 2009 at 7:20 am
ta.bu.shi.da.yu (6/18/2009)
Ah... but how would you get around that? Is there any way of disabling the rounding?
Use FLOOR 🙂
Far away is close at hand in the images of elsewhere.
Anon.
December 11, 2009 at 4:10 am
Added to my knowledge base - default decimal is rounded of.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply