• Ok... this takes 2 seconds longer (1,000,000 rows in 23 seconds instead of 21)... had to work around the "zero domain" on the LOG10 function to get this to work properly for whole numbers...

    DECLARE @TestNum DECIMAL(38,15)

        SET @TestNum = 99   --99.0000

     SELECT CASE

                WHEN FLOOR(REVERSE(ABS(@TestNum))) = 0.0

                THEN 0

                ELSE FLOOR(LOG10(REVERSE(ABS(@TestNum)))+1)

            END

    It does NOT support FLOAT... (the original problem description was based on the DECIMAL datatype so I think we're ok there)... Float does wierd things when you throw a REVERSE on it.  If anyone needs a decimal place counter that works on FLOAT, we'll have to take a different tact...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)