I have 3 columns SPRTELE_PHONE_AREA
, SPRTELE_PHONE_NUMBER
and SPRTELE_PHONE_EXT
- prefix, the number and ext.
I have created a case where I want to display only the SPRTELE_PHONE_NUMBER
if SPRTELE_PHONE_AREA
and SPRTELE_PHONE_EXT
are null. Else if they are not null, the output will be "(prefix)number.ext" with parentheses and dot.
Here is my code:
SELECT
CASE
WHEN SPRTELE_PHONE_AREA IS NULL AND SPRTELE_PHONE_EXT IS NULL
THEN SPRTELE_PHONE_NUMBER
ELSE CONCAT('(', SPRTELE_PHONE_AREA, ')', SPRTELE_PHONE_NUMBER, '.', SPRTELE_PHONE_EXT)
END
FROM
vcc.sprtele;
The problem is the output is displayed as the second case on each record: "CONCAT..."
Where is the problem here?
Example: prefix = 650, number = 1234567, ext = 890
- if prefix and ext are null -> 1234567
- if prefix and ext are not null -> (650)1234567.890
If prefix is null and ext is not null -> 1234567.890 and vice versa