Friday, February 24, 2012

how to quit an sproc

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(rshivaraman@.gmail.com) writes:

Quote:

Originally Posted by

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/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment