when I run anyone of the three below, the returned string in not formatted as desired.
--Option 1
RAISERROR ('Error in % stored procedure', 16, 0, N'usp_InsertCategories');
Msg 50000, Level 16, State 0, Line 2
Error in usp_InsertCategoriestored procedure
Error in usp_InsertCategoriestored procedure
--Option 2
DECLARE
@message AS NVARCHAR(1000) = 'Error in % stored procedure';
RAISERROR (@message,
16, 0, N'usp_InsertCategories s');
Msg 50000, Level 16, State 0, Line 2
Error in usp_InsertCategories stored procedure
Msg 50000, Level 16, State 0, Line 2
Error in usp_InsertCategories stored procedure
--Option 3, in SQL Server 2014
DECLARE
@message AS NVARCHAR(1000) = 'Error in % stored procedure';
SELECT
@message = FORMATMESSAGE (@message, N'usp_InsertCategories');
RAISERROR (@message,
16, 0);
Msg 50000, Level 16, State 0, Line 4
Error in usp_InsertCategoriestored procedure
Msg 50000, Level 16, State 0, Line 4
Error in usp_InsertCategoriestored procedure
Notice there is a space and an 's' missing between usp_InsertCategories and stored procedure.
Workaround:
RAISERROR ('Error in % stored procedure', 16, 0, N'usp_InsertCategories'' s');
Msg 50000, Level 16, State 0, Line 1
Error in usp_InsertCategories' stored procedure