August 26, 2008 at 5:20 am
Hi Folks,
Is it possible to break the execution of subsequent batches if some goes wrong in any one batch? Consider the following scenario:
USE XYZ
GO
IF EXISTS(SELECT 1 FORM LOG WHERE NAME = 'ABC')
BEGIN
PRINT 'ALREADY DONE'
CODE TO BREAK THE SUBSEQUENT BATCHES.... CREATE INDEX STATEMENT SHOULD NOT BE EXECUTED
END
ELSE
BEGIN
IF EXISTS(SELECT 1 FROM SYS.TABLES WHERE NAME = 'ABC')
DROP TABLE ABC
CREATE TABLE ABC(X INT)
END
GO
CREATE INDEX IX_ABC_X ON ABC(X ASC)
GO
Is there some keyword thath I dunno to do this?
August 26, 2008 at 12:51 pm
[font="Arial"]
Hello,
I'm not sure I understand your needs clearly however there are a couple of approaches you may want to try.
There is a batch variable called @@error that you can use to test successful execution.
You could also create a table with a single row and columns that are set to a 0 unless they are successful and then they could show a 1. The next 'batch' would test the table and column for the prior action and if not a 1 then do a halt.
There is also a 'GOTO'' command that you can use to bypass subsequent batches in the sql.
You could also control the 'batch' via a .bat command file that tests for successful return values befor proceeding to the next 'batch' stage.
Hope this helps.
Regards,
Terry
[/font]
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply