user7331448
user7331448

Reputation: 21

SQL Server not displaying message from throw command

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?

Upvotes: 1

Views: 479

Answers (1)

cloudsafe
cloudsafe

Reputation: 2506

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;

Upvotes: 1

Related Questions