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
 General SQL Server Forums
 New to SQL Server Programming
 RAISERROR IN 2008

Author  Topic 

manzoor_mustafa
Starting Member

6 Posts

Posted - 2009-09-08 : 08:09:29
Is it posibble to specify a custom error number associated with RAISERROR statement. By default, SQL SERVER 2008 is assigning "50000".

Issue: Based on the error number returned from Database, custom implementation has to be done in Front End coding. Currently, all errors raised through RAISERROR statement provides "50000" as Error Number(with error messages specific to an error).

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-08 : 08:16:09
You can possibly use sp_addmessage to do this, but you would need to provide an error message as well:

exec sp_addmessage @msgnum = 99999, @severity = 1, @msgtext = 'error msg';
raiserror(99999,1,1);
exec sp_dropmessage @msgnum = 99999;
Go to Top of Page

manzoor_mustafa
Starting Member

6 Posts

Posted - 2009-09-09 : 05:17:23
Thanks. I have another question.

Suppose RAISERROR is called in a CATCH Block to re-throw an error, is it possible to set the error number (instead of 50000 or custom one) with SQL SERVER generated error number.

So the error message alone will be a customized one but ERROR NUMBER remains the same(not custom error number).


Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-09 : 05:27:47
You should get the original error number anyway.

Set a variable to ERROR_NUMBER() and use that in your RAISERROR call.

So:

Declare @ErrNum int
Select @ErrNum = ERROR_NUMBER()
RAISERROR(@ErrNum,1,1)


Does this not raise the correct erro number?
Go to Top of Page
   

- Advertisement -