﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Difference between decimal and smallmoney / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 23:31:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote][b]Eugene Elutin (9/26/2012)[/b][hr]No! Sorry, I was not explicit enough. My post addressed to OP. :blush:[/quote]No worries, just checking in case I was expected to respond.</description><pubDate>Wed, 26 Sep 2012 10:20:27 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote][b]SQL Kiwi (9/26/2012)[/b][hr][quote][b]Eugene Elutin (9/26/2012)[/b][hr]If you work with monetary datatypes you should understand how SQL works with them and when rounding is performed.[/quote]Are you talking to me?[/quote]No! Sorry, I was not explicit enough. My post addressed to OP.:blush:Please check if my edit did make a change...</description><pubDate>Wed, 26 Sep 2012 09:49:35 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote][b]Eugene Elutin (9/26/2012)[/b][hr]If you work with monetary datatypes you should understand how SQL works with them and when rounding is performed.[/quote]Are you talking to me?</description><pubDate>Wed, 26 Sep 2012 08:46:08 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote]...The ranges of the two types have been discussed already, but there is another consideration:[code="sql"]-- Result is $1.0000 typed as smallmoneyDECLARE @credit smallmoney = $1.99;SELECT @credit / 10000 * 10000;GO-- Result is 1.9900000000 typed as decimal (21, 10)DECLARE @credit decimal(9,4) = 1.99;SELECT @credit / 10000 * 10000;[/code]...[/quote]In the above example by Paul White, you can see where the rounding happens and how it can potentially cause issues.So, If you work with monetary datatypes you should understand how SQL works with them and when rounding is performed. Try this one:[code="sql"]-- Result is $1.99 typed as smallmoneyDECLARE @credit smallmoney = $1.99;SELECT @credit * 10000  / 10000;[/code]The reason it works fine for decimal is that SQL converts result of decimal(9,4) division by integer to decimal(21,10)Check this one:[code="sql"]SELECT 1.99  / 10000.00SELECT 1.99  / 10000.0SELECT 1.99  / 10000SELECT 1.9900  / 10000.00SELECT 1.9900  / 10000.0SELECT 1.9900  / 10000[/code]So, I do prefer working with decimals as there are less thing to worry about, but sometimes you stuck with what you have. So, you should know implications and ways around.;-)</description><pubDate>Wed, 26 Sep 2012 08:20:12 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote] 2 datatypes, one can store more digits in less bytes than the other, I must of missed something obvious here.. I'm asking as I wanted to use decimal (9,3) for prices, yet smallmoney uses one less byte and can store bigger numbers. [/quote] The proprietary MONEY data types are leftovers from the 1970's and Sybase. They do display formatting in the database in violation of the principle of a tiered architecture; they do not port; they do incorrect math by rounding too soon. (Google it!)The DECIMAL(s,p) types allow you to adjust the precision to the legally required limits. Ask your accounting department, but 5 decimals shows up in GAAP and EU regulations.</description><pubDate>Wed, 26 Sep 2012 01:35:52 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>Makes sense to me.</description><pubDate>Tue, 25 Sep 2012 15:32:37 GMT</pubDate><dc:creator>terry999</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>[quote][b]terry999 (9/25/2012)[/b][hr]smallmoney type takes up to 4 bytesdecimal(9,4)  can only store  21474.3647 but use one more byte[/quote]The ranges of the two types have been discussed already, but there is another consideration:[code="sql"]-- Result is $1.0000 typed as smallmoneyDECLARE @credit smallmoney = $1.99;SELECT @credit / 10000 * 10000;GO-- Result is 1.9900000000 typed as decimal (21, 10)DECLARE @credit decimal(9,4) = 1.99;SELECT @credit / 10000 * 10000;[/code]This may or may not be important to you, but the characteristics of the data type might be more interesting than saving a byte here or there.  Indeed, there may be no byte to save if row compression is active, or if the extra byte per row does not result in at least one row having to be stored on a separate data page.</description><pubDate>Tue, 25 Sep 2012 10:23:49 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>Decimal(9,3) can store -999,999.999 to 999,999.999Decimal(9,4) is -99,999.9999 to 99,999.9999Not sure, but I think they're stored differently internally - decimal as an integer* with a factor of 10 multiplier, money as a standard integer.E.g. in decimal(9,4), 12345.6789 is stored as 123456789 x 10^-4*(Integer here means the mathematical definition, not the datatype).As precision increases, the bytes needed to store the integer increase to accommodate the maximum possible value.4 bytes is enough to store 999,999,999 but not 9,999,999,999Perhaps the extra byte stores the factor of 10 to multiply by?For smallmoney, you'll notice the maximum value of a 4-byte integer is 2,147,483,647, which equals 214,748.3647 x 10^4, the maximum value of smallmoney. Don't need to store the factor of 10 multiplier as it's always -4 in smallmoney.</description><pubDate>Tue, 25 Sep 2012 09:49:30 GMT</pubDate><dc:creator>Gazareth</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>Then the short answer is, use the variable with the smallest footprint that meets your requirements: in this case, smallmoney.As to the one-byte difference, I can't say definitively as I haven't researched it, but I'd say it has something to do with the need for the decimal type to have varying scale, whereas money and smallmoney are fixed at scale = 4. Research BOL for "datatypes" for more info.</description><pubDate>Tue, 25 Sep 2012 09:26:11 GMT</pubDate><dc:creator>Roland Alexander STL</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>2 datatypes, one can store more digits in less bytes than the other, I must of missed something obvious here..I'm asking as I wanted to use decimal (9,3) for prices, yet smallmoney uses one less byte and can store bigger numbers.</description><pubDate>Tue, 25 Sep 2012 09:20:01 GMT</pubDate><dc:creator>terry999</dc:creator></item><item><title>RE: Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>So...what's your question?</description><pubDate>Tue, 25 Sep 2012 09:16:26 GMT</pubDate><dc:creator>Roland Alexander STL</dc:creator></item><item><title>Difference between decimal and smallmoney</title><link>http://www.sqlservercentral.com/Forums/Topic1364112-1292-1.aspx</link><description>Hismallmoney type takes up to 4 bytes.Monetary data values from -214,748.3648 through +214,748.3647, with accuracy to a ten-thousandth of a monetary unit.Yet decimal(9,4) takes 5 bytes (as I understand it) yet doesn't store as large a range. decimal(9,4)  can only store  21474.3647 but use one more byte</description><pubDate>Tue, 25 Sep 2012 09:09:04 GMT</pubDate><dc:creator>terry999</dc:creator></item></channel></rss>