Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

THROW, SQL 2012

The output from:
use TSQL2012;
GO
DECLARE @message AS NVARCHAR(1000) = 'Error in % stored procedure';
SELECT @message = FORMATMESSAGE (@message, N'usp_InsertCategories');
THROW 50000, @message, 0;

Open in new window

is:
Msg 50000, Level 16, State 0, Line 5
Error in usp_InsertCategoriestored procedure

Question: How can I change my code to produce:
Msg 50000, Level 16, State 0, Line 5
Error in usp_InsertCategories stored procedure
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

For starters, try adding a space at the end...
DECLARE @message AS NVARCHAR(1000) = 'Error in % stored procedure ';

Open in new window

Avatar of Mike Eghtebas

ASKER

I tried it using:
use TSQL2012;
GO
DECLARE @message AS NVARCHAR(1000) = 'Error in % stored procedure ';
SELECT @message = FORMATMESSAGE (@message, N'usp_InsertCategories');
THROW 50000, @message, 0;

Open in new window


I still get:
Msg 50000, Level 16, State 0, Line 18
Error in usp_InsertCategoriestored procedure
ASKER CERTIFIED SOLUTION
Avatar of PWinter
PWinter
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this (& yes, the placement of the semi-colons is deliberate)
DECLARE @message AS NVARCHAR(1000) = 'Error in % stored procedure '
SET @message = FORMATMESSAGE (@message, N'usp_InsertCategories')
;THROW 50000, @message, 0;

Open in new window

@PWinter

In addition to the blank space after N'usp_InsertCategories ', I need to add an extra s to 'Error in % sstored procedure'; in order to work. otherwise I was getting the messgae like:

Msg 50000, Level 16, State 0, Line 6
Error in usp_InsertCategories tored procedure

not like (as it was expected):
Msg 50000, Level 16, State 0, Line 6
Error in usp_InsertCategories stored procedure

@Paul, I got:
Msg 50000, Level 16, State 0, Line 6
Error in usp_InsertCategoriestored procedure