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 |
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-10 : 09:17:26
|
| I have a procedure there i am having some update statement and some insert statement..If any error occurs i want to complete the execution of all the statement but want to return the integer 0 else 1 if all success.Can anyone suggest me how to achieve this...Please help me out...Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-10 : 09:36:08
|
| For each statement check the value of @@Error assign the variable accordinglyMadhivananFailing to plan is Planning to fail |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-05-10 : 09:53:49
|
| @@RowCount or @@Error?--Gail ShawSQL Server MVP |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-10 : 10:01:15
|
quote: Originally posted by GilaMonster @@RowCount or @@Error?--Gail ShawSQL Server MVP
It should be @@ErrorI corrected it nowThanks MadhivananFailing to plan is Planning to fail |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-11 : 02:11:35
|
| Yes thats correct but i have a lot of statements other than insert update commands because error may occurs in select statement also so do i need to check @@Error just after each statement or any other way to achieve it...Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-05-11 : 03:23:19
|
| You need to check @@Error after every statement.--Gail ShawSQL Server MVP |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-11 : 03:40:20
|
| But in the mean time i explored something different that if any error occured by default its not possible to execute the next statement control will come out of the proc.so i m surprised how the @@Error can be used please anybody give me such example to use it.Thanks in advance...Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-05-11 : 04:59:55
|
quote: Originally posted by vaibhavktiwari83 But in the mean time i explored something different that if any error occured by default its not possible to execute the next statement control will come out of the proc.
That's not at all true. Depends on what kind of error it is. If it's a statement-terminating error (quite common) then the statement fails and execution continues at the next statement. Control does not leave the proc.--Gail ShawSQL Server MVP |
 |
|
|
|
|
|