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 |
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2011-03-15 : 23:08:57
|
I'd like to add error handling for insert statement of Table1. If it fails ,need to update Table2 columnA to 0 . If it succeeds, need to update Table2 columnA to 1.How the query looks like ?Thanks. |
|
sp3010
Starting Member
8 Posts |
Posted - 2011-03-16 : 01:13:39
|
Declare @ErrorCode intSelect @ErrorCode = @@ErrorIf @ErrorCode = 0Begin Insert table1 Select @ErrorCode = @@ErrorEndIf @ErrorCode = 0 Begin Insert ?table2 with 0 Select @ErrorCode = @@Error endelse Begin --Another statement Insert ?table2 with 1 Select @ErrorCode = @@Error endelseEndReturn @ErrorCode |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-03-16 : 04:18:52
|
Also read about error handling article from Erland Sommarskog.MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|