I am trying to update 3 different columns in a table based on 3 different conditions in the where clause. (I have the updated data in a different table, so I am joining them on the primary keys)
For example, if I did not have a value previously in field1 for a customer but now I do, I should be able to update the column 'field1'. Similarly, I would like to update columns field2 and field3.
Can I accomplish this in a single Update statement.
To Update one column you can write something like this:
Update tblCustomer
SET tblCustomer.Order_Date = tblCustomerInfo.Order_Date
FROM tblCustomer
LEFT JOIN tblCustomerInfo ON (tblCustomer.CustomerID = tblCustomerInfo.CustomerID)
WHERE tblCustomer.Order_Date <> tblCustomerInfo.Order_Date
AND tblCustomer.Order_Date is NULL;
How about updating 3 different Columns in single go based on different where conditions (if the data was missing for that column was missing previously, and is now available)