Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
level88
Starting Member
5 Posts |
Posted - 2009-03-06 : 20:10:53
|
Hi, I have encountered a weird error. It seems that an insert statement didn't execute and the process didn't error out and continued on. Here's the logic:step 1: (insert into table, values xxx)step 2: increment counterThe problem is that the procedure ran 5 times and at step 2, the counter was incremented every time but the insert didn't happen at step 1. It seems to happen about once in every 5000 executions of the procedure. Is there some logical explanation for this? If the insert fails at step 1, shouldn't it error out and end right there? |
|
guptam
Posting Yak Master
161 Posts |
Posted - 2009-03-06 : 21:19:52
|
Does the table have any kind of triggers? That could be rolling back the data?-- Mohit K. GuptaB.Sc. CS, Minor JapaneseMCITP: Database AdministratorMCTS: SQL Server 2005http://sqllearnings.blogspot.com/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
level88
Starting Member
5 Posts |
Posted - 2009-03-06 : 21:49:31
|
quote: Originally posted by guptam Does the table have any kind of triggers? That could be rolling back the data?
Hi, thanks for the reply. I didn't set up any triggers on the table. The problem just doesn't make sense. |
|
|
level88
Starting Member
5 Posts |
Posted - 2009-03-06 : 21:53:26
|
quote: Originally posted by tkizer You'll need to post the code in order for us to help.
Ok, here it is:BEGIN TRANINSERT INTO Feedback (fdbOAid,fdbText,fdbRating,fdbRaterID,fdbUserID,fdbDate,fdbBS,fdbDateDiff) VALUES (@tmpOrderID,@tmpText,@tmpRating,@tmpUserID,@tmpCommentedOnID,@tmpDate,@tmpBS,@tmpDateDiff)IF @tmpBS = 'B' UPDATE Orders SET OrderSellerFdb = @tmpRating + 1 WHERE OrderID = @tmpOrderIDELSE UPDATE Orders SET OrderBuyerFdb = @tmpRating + 1 WHERE OrderID = @tmpOrderIDIF @tmpRating = 0 UPDATE Users SET User_Feedback = User_Feedback + 1 WHERE UserID = @tmpCommentedOnIDIF @tmpRating = 2 UPDATE Users SET User_Feedback = User_Feedback - 1 WHERE UserID = @tmpCommentedOnIDIF @@ERROR = 0 COMMIT TRANELSE ROLLBACK TRANThe insert didn't happen but the UPDATE Users SET User_Feedback = User_Feedback + 1 did. Thanks. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|