There could be a table change in between that causes the sum variable to be incremented too often. This article should help you: