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
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
For starters, try adding a space at the end...
DECLARE @message AS NVARCHAR(1000) = 'Error in % stored procedure ';

Open in new window

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
PWinterCommented:
Try this:
DECLARE @message AS NVARCHAR(1000) = N'Error in % stored procedure';
SELECT @message = FORMATMESSAGE (@message, N'usp_InsertCategories ');

Open in new window

Good luck.
PW

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PortletPaulEE Topic AdvisorCommented:
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

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
@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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.