Reputation: 1295
I feel like this is a pretty basic SQL question but I am having trouble searching for the answer.
Essentially the logic I want to write in my SQL statement is this.
When doing an update on a row instead of just blanking out the data there add it together.
so if I have a row "9/19/13" | 0 | 1 | 0
and now I want to update that row with this entry "9/19/13" | 0 | 1 | 0
I get "9/19/13" | 0 | 2 | 0
.
My current update command looks like so.
UPDATE entries(Date, John, Mark, Casey) SET (@Date, @John, @Mark, @Casey) WHERE(Date = @Date);
I could easily do it in my actual code where I would retrieve the entry increment it then just do a regular update, but I feel like it should be possible to to do it with straight SQL, and would be cleaner.
Upvotes: 0
Views: 56
Reputation: 2295
calling update is just setting the values in the db to be the values you pass in, not the existing value added (in the case of numbers) to the value you're updating with.
it would be much simpler to just increment the value before update as you already have it.
Upvotes: 0
Reputation: 25053
Is this what you mean?
-- @John, @Mark, @Casey are set in advance
UPDATE entries(Date, John, Mark, Casey)
SET (@Date, John + @John, Mark + @Mark, Casey + @Casey)
WHERE (Date = @Date);
Upvotes: 3