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)
 Raiserror Oddity

Author  Topic 

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-12-09 : 17:17:47
I always thought there wasnt a way to have raiserror return a custom code other than 50000 without storing the message using sp_addmessage, but this works. Was it always this way? I dont see this usage (without parens) documented in BOL, or am I overlooking something?


declare @ErrorMessage varchar(max),
@ErrorNumber int

begin try
raiserror 50005 'yak'
end try
begin catch
select error_message(), error_number ()

select @ErrorMessage = error_message(),
@ErrorNumber = error_number()

raiserror @ErrorNumber @ErrorMessage
end catch

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-12-09 : 17:22:20
Mystery solved (sorry)

http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/81ef8f38-7ddc-486b-983c-18dbf7be412d
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-09 : 17:25:23
was always this way...at least since sql 2000, can't remember if it worked in sql 07
Go to Top of Page
   

- Advertisement -