what datatype in sql 2000/2005 should i use for this numeric input that has two decimal value?
ex. 1.22
Printable View
what datatype in sql 2000/2005 should i use for this numeric input that has two decimal value?
ex. 1.22
How many digits to the left of the decimal point? If one, decimal (3,2).
just 2 digits (right) from the decimal point.
ex. xxxxxx.22
We use MONEY - even though it potentially stores 4 digits to the right of the decimal point, it format's nicely to 2 digits with CONVERT() and CAST() functions.
What about LEFT of the decimal point? What is the maximum value that this field can hold?Quote:
just 2 digits (right) from the decimal point.
999,999.99 - use decimal (8,2) -> 8 digits in total (Precision) with 2 decimal points (Scale)
999,999,999.99 - use decimal (11,2) -> 11 digits in total with 2 decimal points
The Precision determines the number of bytes SQL Server will use for this field. The two declarations above will take up 5 bytes and 9 bytes respectively. Max Precision is 38.
Money datatypes require an explicit conversion to character datatypes, ie you must use Cast and/or Convert. Decimal datatypes are implicitly converted by sql server.
We use MONEY for several reasons - not like it's important - but I thought I would mention them.
We only use a handful of datatypes - INT, TINYINT, MONEY, DATETIME and VARCHAR().
Based on the old keep-it-simple concept...
MONEY links up nicely with CURRENCY in VB6 ...
but I think that we have recently discovered that CURRENCY is no longer a datatype in VB.Net - so I see a change coming down the road...
thanks very informative.