Simply putting, scale of an SQL decimal number is the number
of digits appearing after the decimal point.
Examples:
Scale of 9.8 is 1
Scale of 3.142 is 3
Scale of 17.123456789 is 9
How to find the scale of a decimal number?
Sometimes, in the life of a SQL developer, there comes a
scenario where you have to check for the scale of a decimal number to cater
some changes made on other layers of development environment. For instance, if
a UI change is made and it does not allow entering a value in a specific field
that is more than, say, 2 decimal points, all values in the database for the
specific field should be set to a scale of 2.
A very easy way to find the scale of a decimal point using
SQL is as follows:
SELECT LEN(SUBSTRING((CAST(333.45657 AS nvarchar(max))),CHARINDEX('.',(CAST(333.45657 AS nvarchar(max))))+1,LEN(CAST(333.45657 AS nvarchar(max)))))
Comments
Post a Comment