title: How to remove the seperator if all values are NULL in MySQL CONCAT_WS?
body: <p>I am trying to use CONCAT_WS to generate a subject line. However, I want to ignore the seperator if a value is null.</p>
  
  <p>Please look at this query</p>
  
  <pre><code>SELECT
  CONCAT_WS(" ",
  CASE WHEN total_attempts &gt; 0 THEN
  CONCAT( call_code_title , " - ", total_attempts, "&lt;sup&gt;",
      CASE WHEN total_attempts = 2 THEN "nd"
      WHEN total_attempts = 3 THEN "rd"
      ELSE "th" END
  , "&lt;/sup&gt; attempt") ELSE call_code_title END
  , "-", program_name) AS callSubject
  FROM table
  </code></pre>
  
  <p>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</p>
  
  <p>How do I do that?</p>
  
  <p>Thanks</p>