Friday, February 24, 2012

data types

What is the best data type to use within SQL server in a field for
storing currency?

Regards,
CiarnOn 10 Mar 2005 06:17:03 -0800, chudson007@.hotmail.com wrote:

>What is the best data type to use within SQL server in a field for
>storing currency?

Hi Ciarn,

DECIMAL(??,2), with ?? denoting the total number of digits (including
the cents). So if the maximum value is 5 million, you use DECIMAL(11,2).

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||(chudson007@.hotmail.com) writes:
> What is the best data type to use within SQL server in a field for
> storing currency?

Hm, what do you mean with "currency"? If you mean amounts, a decimal(n, 2)
as Hugo suggested can be a good idea. Note, though, that for some reason
the money data type has four decimals.

If you are talking about currency prices, such as how many USD you need
by one 1 EUR, then you need many decimals. Usually currency prices go
with six decimals, but often you also need the reverse, and if you
store with six decimals only, the inverted price will suffer a rounding
error. So I would recommend floats in this case.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

No comments:

Post a Comment