Is there a command in Microsoft SQL Server T-SQL to tell the script to stop processing? I have a script that I want to keep for archival purposes, but I don't want anyone to run it.
To interrupt an Interactive SQL command: To interrupt an Interactive SQL command, select Interrupt the SQL Statement from the toolbar, or select SQL > Stop.
Terminating the statement before the WITH keyword with a semicolon will all it to execute without errors: ;WITH Ms AS (...) ... A MERGE statement must be terminated by a semi-colon (;).
An alternate solution could be to alter the flow of execution of your script by using the GOTO
statement...
DECLARE @RunScript bit; SET @RunScript = 0; IF @RunScript != 1 BEGIN RAISERROR ('Raise Error does not stop processing, so we will call GOTO to skip over the script', 1, 1); GOTO Skipper -- This will skip over the script and go to Skipper END PRINT 'This is where your working script can go'; PRINT 'This is where your working script can go'; PRINT 'This is where your working script can go'; PRINT 'This is where your working script can go'; Skipper: -- Don't do nuttin!
Warning! The above sample was derived from an example I got from Merrill Aldrich. Before you implement the GOTO
statement blindly, I recommend you read his tutorial on Flow control in T-SQL Scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With