I am trying to use CONCAT_WS to generate a subject line. However, I want to ignore the seperator if a value is null.
Please look at this query
SELECT
CONCAT_WS(" ",
CASE WHEN total_attempts > 0 THEN
CONCAT( call_code_title , " - ", total_attempts, "<sup>",
CASE WHEN total_attempts = 2 THEN "nd"
WHEN total_attempts = 3 THEN "rd"
ELSE "th" END
, "</sup> attempt") ELSE call_code_title END
, "-", program_name) AS callSubject
FROM table
The problem is when "program_name" IS NULL then I always will have "-" at the end of the string. I want to not concat "-" id program_name IS NULL
How do I do that?
Thanks