I would like to update the record with two dates, leaving the existing data intact if I do not have a new value to update.
Here is an example table entry:
id last_foo last_bar
-- ---------- ----------
1 2010-05-30 2010-05-30
And the query I use:
UPDATE sampledates
SET last_foo = @LastFoo,
last_bar = @LastBar
WHERE id = @ID;
If my values โโare null LastFoo or LastBarnull, I would like to leave the existing SQL value as it is, otherwise an update.
For example, let's say I update this entry with the following values โโ(this is C #, but any language applies):
DateTime? LastFoo = new DateTime('2010-06-04');
DateTime? LastBar = null;
I would like the entry to be as follows:
id last_foo last_bar
-- ---------- ----------
1 2010-06-04 2010-05-30
I understand that I can change the query text to omit the second column if the value is null, but I was wondering if there is a way to leave the query as is and indicate that I am not changing the specified column.