How do I update selective fields in SQL (leaving some unchanged)?
问题 I would like to update a record with two dates, leaving existing data intact if I do not have a new value to update with. Here is a sample table record: id last_foo last_bar -- ---------- ---------- 1 2010-05-30 2010-05-30 And the query I am using: UPDATE sampledates SET last_foo = @LastFoo, last_bar = @LastBar WHERE id = @ID; If my nullable datetimes LastFoo or LastBar are null, I would like to leave the existing SQL value as-is, otherwise update. For example, say I am updating this record