Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 User Generated Exceptions

Author  Topic 

mccallug
Starting Member

6 Posts

Posted - 2008-07-22 : 17:19:45
Is it possible to throw an exception from within a stored procedure? I tried raising an erro but I need the error to hault the programming calling the stored procedure and provide it with some error details.

Thanks.

----------Code------------
SET @TEMP = (SELECT COUNT(*) FROM Parts WHERE PartNumber = @PN)
IF(@TEMP <> 1)
BEGIN
RAISERROR('PartNumber does not exist in numbering system. Please contact a system administrator to add this part to the
system', 1, 1)

RETURN
END
.
.
.
.
.
.
RETURN

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-07-23 : 01:59:35
Look into sql 2005 error handling

http://weblogs.asp.net/alex_papadimoulis/archive/2005/02/02/365685.aspx
Go to Top of Page

mccallug
Starting Member

6 Posts

Posted - 2008-07-23 : 17:02:07
Thanks. It works great.

I tried that before but had no luck. I was setting the Error_Number to 1 and the Error_State to 1. Do you know if there are specific error state/number that will throw exceptions?
Go to Top of Page
   

- Advertisement -