SQLTeam.com | Weblogs | Forums

T-sql 2012 update


#1

In t-sql 2012 prior to an update statement, I have a count of records which is 5039. In the Update statement there is rows affected = 4999. When I run a select after the update, it looks like 5039 records were updated.

Since there is a difference in the counts, is there a way to show what rows were updated in the update statement? Also is there a way to show what rows did not get updated in the update statement?

If so, can you show me the sql on how to accomplish this goal? If not, do you have any suggestions on what I can try to determine where the discrepancy exists?


#2

If you have a JOIN in the COUNT / UPDATE statement then it is possible that a single row in the table you are updating joins to more than one row in the joined table. The COUNT() will include all the JOINed rows, whereas the UPDATE will only update the row once, so the COUNT(*) may be higher.


#3

would you show me the sql you are referring to?