title: SQL - Update with a CASE statement, do I need to repeat the same CASE multiple times?
body: <p>My UPDATE statement goes along the lines of:</p>
  
  <pre><code>UPDATE  customer
  SET  forenames=ot.forenames,
       surname =
  
  CASE WHEN ot.safeplace IS NULL
  THEN 'test SAFEPLACE IS NULL'
  ELSE 'test Safeplace IS NOT NULL'
  END,
  
       middlename =
  
  CASE WHEN ot.safeplace IS NULL
  THEN 'test2 SAFEPLACE IS NULL'
  ELSE 'test2 Safeplace IS NOT NULL'
  END,
  
  FROM    order_transaction ot
  
  WHERE   customer.custid = ot.custid
  AND ot.trans_orderid = 5678
  AND customer.custid = 1234
  </code></pre>
  
  <p>The above works. It basically checks if a field in another table is NULL or not, and then updates the customer's "surname" and "middlename" accordingly. As you can see above, I have repeated the same CASE statement twice. My question is - is there a way I can specify the CASE statement just once?</p>
  
  <p>The point is, if I say wanted to update 10 fields based on a certain condition, do I need to include 10 similar CASE conditions? Or can the SQL be improved to have just one CASE, and 10 field updates within the WHEN / ELSE clauses?</p>
  
  <p>(I'm using a Postgresql 8.2 database but I believe the above is standard SQL).</p>
  
  <p>Many thanks,
  Rishi</p>