Is there any way of stopping a script running?
In my script if a test is true(eg a certain table doesn't exists), i want to stop any further execution of the script.Assuming that you have already looked at IF...ELSE and it does not work for you, you might consider WHILE.
Look in SQL BOL under "control of flow"
Regards,
hmscott|||you can bracket the block of code in IF clause, say if table exists, then do this..
In stored proc, you can also use RETURN to exit out of the code.|||Originally posted by jagnini
Is there any way of stopping a script running?
In my script if a test is true(eg a certain table doesn't exists), i want to stop any further execution of the script.
The RETURN statment will end a script|||Actually, a return will just send you to the next batch terminator (go). Try out the script below in a pubs database:
select *
from authors
return
select *
from titleauthor
go
select *
from titles|||Thats the situation we have; we have several sections with "go"s.
It would be a bit of a pain to put a test in at the beginning of each section.|||Check out GOTO, but you'll have to get rid of all your "GO"'s, except for the last one if you want to keep it. It just has to be after all labels that the GOTO can go to ;)|||Can you get rid of the GOs and use nested transactions?
BEGIN TRANSACTION TRAN_WRAPPER
BEGIN TRANSACTION TRAN1
IF @.@.ERROR<>0
BEGIN
ROLLBACK TRANSACTION TRAN_WRAPPER
END
COMMIT TRANSACTION TRAN1
BEGIN TRANSACTION TRAN2
IF @.@.ERROR<>0
BEGIN
ROLLBACK TRANSACTION TRAN_WRAPPER
END
COMMIT TRANSACTION TRAN2
COMMIT TRANSACTION TRAN_WRAPPER
This would roll back the entire process. Just a thought. I'm not sure what you're trying to do between the batches. :)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment