Slashing last the three zeros on a currency field

  • We have been told to slash the last three zeros of our currency by the authorities. I am trying to come out with a script that will locate every currency field in the database and divide it by 1000 to comply with the new regulation e.g if database value is $1000 it should be reduced to $1. Can someone drop me a sample script that can achieve that?

  • Clement

    Assuming all currency fields in your database have the "money" data type, this will generate a script that will change your values as required.

    John

    SELECT 'UPDATE ' c.TABLE_NAME ' SET ' c.COLUMN_NAME ' = ' c.COLUMN_NAME '/1000.000'

    FROM INFORMATION_SCHEMA.COLUMNS c JOIN INFORMATION_SCHEMA.TABLES t

      ON c.TABLE_NAME t.TABLE_NAME

    WHERE c.DATA_TYPE 'money'

      AND t.TABLE_TYPE 'BASE TABLE'

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply