Home > OS >  can we give datatype as decimal(2,2) or decimal(3,3) in SQL server ,
can we give datatype as decimal(2,2) or decimal(3,3) in SQL server ,

Time:12-16

will it work according to the rules ??? I want to know it is correct or not?

I have error of arithmetic overflow error converting datatype to datatype numeric

I know we can write decimal(6,2) for the value 1000

output:- 1000.00

CodePudding user response:

The short answer is yes. The following is from the SQL Server docs, which I'd recommend reading through for better understanding.

The decimal type is defined as decimal[ (p[ ,s] )]

In the above statement, p represents precision, and s represents scale, which are both fixed numbers. When maximum precision is used, valid values are from - 10^38 1 through 10^38 - 1.

p is the maximum total number of decimal digits to be stored. This number includes both the left and the right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.

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

CodePudding user response:

Yes you can.
Possible values range from 0.999 to -0.999

You can test that by casting a value to the data type

select cast(0.999 as decimal(3,3))

and see if it works or generates an arithmetic overflow.

  • Related