In MS SQL, I need a approach to determine the largest scale being used by the rows for a certain decimal column.
For example Col1 Decimal(19,8) has a scale of 8, but I need to know if all 8 are actually being used, or if only 5, 6, or 7 are being used.
Not pretty, but I think it should do the trick:
-- Find the first non-zero character in the reversed string... -- And then subtract from the scale of the decimal + 1. SELECT 9 - PATINDEX('%[1-9]%', REVERSE(Col1))