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 |
Gold
Starting Member
4 Posts |
Posted - 2007-07-14 : 17:38:35
|
The situation is the following: I have a script that contains more then one batch of SQL DML statements and I want to interrupt script execution if any one of the SQL DML statements returns zero rows affected.Thanks in advance to anyone that has some insight about this situation. |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-07-14 : 20:04:49
|
Check @@rowcount after every dml, exit the script if result is 0. |
|
|
Gold
Starting Member
4 Posts |
Posted - 2007-07-15 : 06:53:52
|
That's precisely what I'm looking for. A way to exit the entire script and not just the current executing batch, but I don't know the code to do that.So if you could tell me the T-SQL code to do the exiting part, that would be great. |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-07-15 : 20:41:29
|
Try goto statement to jump to the end. |
|
|
Gold
Starting Member
4 Posts |
Posted - 2007-07-16 : 04:46:33
|
The GOTO cannot jump to a label outside of the batch so does not accomplish what I'm trying to do, but thanks for the replies anyway. |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-07-16 : 10:23:13
|
Create a temp table at the beginning of the script.When you reach your exit condition, set a flag in the table.Check the table in the rest of your batches, and exit if the condition is set.CODO ERGO SUM |
|
|
Gold
Starting Member
4 Posts |
Posted - 2007-07-16 : 13:23:48
|
Thanks, that did the trick. |
|
|
|
|
|