frenchie
frenchie

Reputation: 51937

defining decimal data type in sql server

I want to save timezones in a table. Numbers will range from -12 to +12 and some numbers will have a decimal portion (ie -4.30). I know about the timezoneoffset but I prefer not to use it.

I declared a decimal (2,2) but it's not working as expected. I originially had the column defined as a tinyint; I changed all the values to 0 and then changed the datatype to the decimal (2,2) but now I can't seem to store the values I need.

Thanks for suggestions.

Upvotes: 0

Views: 1247

Answers (2)

Noel
Noel

Reputation: 600

Try decimal(4,2)

From MSDN:

decimal[(p[, s])] and numeric[(p[, s])]

Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The SQL-92 synonyms for decimal are dec and dec(p, s).

p (precision)

Specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision. The maximum precision is 38. The default precision is 18.

s (scale)

Specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.

Upvotes: 4

Andomar
Andomar

Reputation: 238086

You're probably looking for decimal(3,1): 3 numbers total, one of which is behind the comma.

See the MSDN documentation.

Upvotes: 1

Related Questions