Groups | Blog | Home
all groups > sql server clients > december 2004 >

sql server clients : Killing mupltiple batches



Greg Michalopoulos
12/17/2004 2:00:03 PM
Is there a SQL command which will kill or exit all batches in the query
analyzer?

For example I have this script:

query1
query2
GO
query3
query4
query5
GO

Is there a way so that when I check @@ERROR after query1 that query2,3,4,5
do NOT get executed? GOTO's cannot see beyond the next GO.

Thanks,
Greg

Jacco Schalkwijk
12/20/2004 12:17:21 PM
There is no neat way to do this in Query Analyzer except raising an error
with severity 20 or higher, which will terminate your connection:
RAISERROR ('Your message here.', 20, 1)
If you use osql to run a script, you can raise an error with a status of
127, which will have the same effect, but won't leave traces in the SQL
Server error log like raising an error with status 20 does.
RAISERROR ('Your message here.', 16, 127)

--
Jacco Schalkwijk
SQL Server MVP


[quoted text, click to view]

Joel Mariano
1/21/2005 9:07:03 AM
Hello I had a similar problem as original poster - needing to kill multiple
batches within the same script.

Raiserror is not working for me.

raiserror ('just kill me now',19,1, 'WITH LOG,NOWAIT')

comes back with
Server: Msg 2754, Level 16, State 1, Line 1
Error severity levels greater than 18 can only be specified by members of
the sysadmin role, using the WITH LOG option.

I am sure that the account i am using has the sysadmin fixed server role.

PLEASE HELP!

Thanks,
Joel Mariano

[quoted text, click to view]
Joel Mariano
1/21/2005 1:29:08 PM
Whoops, brain fart:

raiserror ('just kill me now',20,1) WITH LOG,NOWAIT

works just fine (drops the connection).


[quoted text, click to view]
AddThis Social Bookmark Button