Search code examples
sqldb2-400punctuation

How to make temporary column without punctuation in SQL


I have the following table1

ID | TAX
---+--------------------
 1 | 99.999.999.9-999.999
 2 | 99.999.999.9.999.999
 3 | 99.999.999.9,999,999
 4 | 99.999999-9-999-999

I want to create a new column TEMP_TAX, but this column is only a temporary query, expected output results (NOT PUNCTUATION [,.-]):

ID | TAX                  | TEMP_TAX
---+----------------------+-----------------
 1 | 99.999.999.9-999.999 | 999999999999999
 2 | 99.999.999.9.999.999 | 999999999999999
 3 | 99.999.999.9,999,999 | 999999999999999
 4 | 99.999999-9-999-999  | 999999999999999

Can someone help with the query? Thank you before.


Solution

  • select id, tax, replace(replace(replace(tax, '.', ''), '-', ''), ',', '')
    from mytable