MySQL – How to replace a given value from multiple columns when using SELECT

MySQLselect

I need to SELECT a set of rows of a given table whose structure looks like – 1ยบ line is the name of columns

    A01    A02    A03    A04    A05  ... A200

  99999  99999     10    753  99999     99999

As you can see, it has about 200 columns. It uses 99999 to model a NULL or undefined value. So, in my SELECT, i need to replace those values with NULL or even a empty String. Is it possible by using a single SELECT or should i use something else ?

ATT: you could suggest UPDATE those values with NULL – and then SELECT -, but it is a legacy system which we cannot modify them

Best Answer

SELECT IF(A01 = 99999, NULL, A01) AS A01,
       IF(A02 = 99999, NULL, A02) AS A02,
       ...
    FROM ...

(For empty string, use '' instead of NULL.)