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 |
|
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2008-04-09 : 18:47:25
|
Ive got an insert statement that fails, and below that I have code like the following: IF @@ERROR <> 0 BEGIN -- Roll back the transaction ROLLBACK -- Raise an error and return RAISERROR ('Error INSERT INTO Address.', 16, 1) print 'test was here' RETURN ENDHowever, there is now rollback and the inserts below it are going through.what do i have wrong ? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-04-09 : 19:10:54
|
| Are there any statements between the "INSERT" and the "IF @@ERROR" ? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-09 : 19:17:12
|
| Is it in a stored procedure? Could you post the whole thing so that we can make sure it is correct?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2008-04-10 : 09:22:38
|
quote: Originally posted by Lamprey Are there any statements between the "INSERT" and the "IF @@ERROR" ?
Yes, and apparently thats what my problem was. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 09:29:50
|
@@ERROR is highly volatile. It is set to new value after every statment.And even referring to @@ERROR sets @@ERROR to 0. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 09:31:06
|
You can do a "workaround".INSERT ..SET @MyErrorVariable = @@ERROR... More code here ...IF @MyErrorVariable <> 0 ROLLBACK E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|