Skip to content
Advertisement

Concatenation, rounding, and dealing with nulls

I have the following table:

And I want to produce the following column:

But I’m having difficulty dealing with the rounding that occurs when using coalesce to convert potential null values to 'null'. Trying this:

Gives me the error Numeric value 'null' is not recognized. Even a simple select concat(cast(x as char), cast(y as char)) doesn’t produce the desired results, although no error occurs.

Technically, the following works (using REGEXP_REPLACE). But this seems a bit hacky. Is there a better documented way of doing this?

Advertisement

Answer

Your value are strings, not ints. So, convert them to the right type:

Note: Not all databases support varchar(255) in this context and need something like string or char.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement