As suggested by Sunny, you can try using Trim functions as your Condition.
Also, worth checking how are your values in 'MESSAGE_CODE' coming in QV and if you are getting '0' ?
It could sometimes be an issue with the Flag/ Binary numbers,
Try using Exists () function in your Condition.
Hope it helps !
I see two problems - one in the question, and one in the suggested answers...
1. The way your IF statement is formulated, you want to use the Code when the Code value doesn't exist - so, every time the code value is NULL, you want to see NULL in your field. It sounds "upside-down" to me. Usually we ask "if this value is NOT NULL, then use it, otherwise use another value".
2. In the suggested solutions, people keep suggesting to use TRIM(LEN(...)), which is meaningless. The function len returns the Length of the field, which is a number. The function TRIM is only useful when it's applied to the field itself, not to its length. So, if anything, the following can be considered:
This combination of the two functions will first trim the spaces on both ends of the field, and then calculate the length of the remaining value. The meaning is to treat any number of spaces the same way as empty strings.