dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Enterprise
Expertise: Intermediate
Feb 25, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Make RAISERROR Your Last Command in Stored Procedures or Triggers

If you execute a SQL statement in a stored procedure after your use the RAISERROR command, you will clear @@ERROR. This is true even if you use a RETURN and return a non-zero value in the stored procedures. For example:
 DECLARE @intReturn int
     , @vcErrorMessage varchar(255)
     , @BeginTransCount int

SELECT @BeginTransCount = @@TRANCOUNT 
-- line above is needed if transaction processing

-- run some SQL command
IF @@error <> 0
BEGIN
     SELECT @intReturn = -1
          , @vcErrorMessage = "An error 
occurred performing some operation."
     GOTO error
END

-- more code...

error:

IF @intReturn IS NULL
BEGIN
     IF @@TRANCOUNT > @BeginTransCount COMMIT  TRANSACTION
END
ELSE
BEGIN
     IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
     RAISERROR ( @vcErrorMessage, 16, 1)
END
GO
David Satz
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date