I am working on a cancer database and I have one column with the date of a patient’s local recurrence (if they had one), and another column with the date of a patient’s distant recurrence (if they had one). I want to create another column that consists of the date of FIRST recurrence, regardless of whether it was local or distant. I’m not sure how to proceed because some patients only had local or only had distant, and thus many fields are “NULL”. Here’s an example of what I’m looking to do:
Date_Local Date_Distant Date_Any
2010-08-01 2009-05-25 2009-05-25
NULL 2001-01-07 2001-01-07
1999-12-12 NULL 1999-12-12
NULL NULL NULL
Assuming your already added the column with an
ALTER TABLEstatement, you would populate it using aCASEstatement in theUPDATEquery like:The above statement will update all rows since it has no
WHEREclause. Before doing theUPDATE, test it out with aSELECTto make sure it looks like you expect:Consider, however, whether you really even need another column added though. Depending on how often you intend to query this, you might just create a view using the
SELECTstatement above instead, so theDate_Anyvalue will be “live”.