how to quit an sproc
am 07.06.2007 15:27:15 von rshivaraman
Hi
I am doing a check and on failing, i have a raiseerror command.
I was assuming, once proc reaches raiseerror, it would stop the proc,
but i see that the proc gives me an error message, but continues to
run thru all the rest of the steps after raiseerror.
how do i make the proc quit after reading raiseerror, only thru
labels ?
IF @CheckIFFileHasOnlyOneOutputType > 1
BEGIN
RAISERROR ('Process Stopped. Input xls file is invalid, as it has more
than one output type specified in the OutputType Column', 16, 1)
END
--more proc steps are here ...
Thanks in advance :
RS
Re: how to quit an sproc
am 07.06.2007 15:59:45 von Erland Sommarskog
(rshivaraman@gmail.com) writes:
> I am doing a check and on failing, i have a raiseerror command.
> I was assuming, once proc reaches raiseerror, it would stop the proc,
> but i see that the proc gives me an error message, but continues to
> run thru all the rest of the steps after raiseerror.
> how do i make the proc quit after reading raiseerror, only thru
> labels ?
Which version of SQL Server are you using?
In SQL 2000 you will need to use the RETURN statement. Preferrably you
return a value > 0, so that the caller knows that things went wrong.
On SQL 2005 you can embed the code in BEGIN TRY END TRY, and then in
BEGIN CATCH END CATCH have some generic error handling, including a
RETURN statement.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx