SQL Server not displaying message from throw command

426 views Asked by At

I am trying to return custom messages in a SQL Server stored procedure based on errors generated using the throw command. The ERROR condition appears to be generated because it is being passed back to the calling code. However, the custom message is not being displayed.

Here is the snippet of code (@msg and @rowcount are declared earlier in the procedure):

set @msg = cast(@rowcount as varchar(5)) + ' records updated';

throw 53000,@msg,1;

Any ideas?

1

There are 1 answers

0
cloudsafe On

Make sure @msg is declared as an nvarchar and allow alternative 0 using isnull if @rowcount is null.

Declare @msg nvarchar(50)
set @msg = cast(isnull(@rowcount,0) as nvarchar(5)) + N' records updated';
throw 53000, @msg,1;