MSDN contains the following syntax:
RAISERROR ( { msg_id | msg_str | @local_variable }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]
msg_strexpects a string up to 2047 characters long, but truncates longer strings. It also has the ability to substitute parameters that truncate the message more than the number of characters provided by the values:
The error message can contain a maximum of 2047 characters. If the message contains 2048 or more characters, only the first 2044 are displayed and an ellipsis is added to indicate that the message has been truncated. Note that substitution parameters consume more characters than the result shows due to the behavior of internal memory. For example, the% d substitution parameter with an assigned value of 2 actually produces one character in the message line, but also internally occupies three additional storage characters. This storage requirement reduces the number of characters available for displaying messages. When msg_str is specified, RAISERROR raises an error message with error number 50000.
severity expects a number from 0 to 25, but corrects other numbers:
0 18 . 19 25 sysadmin ALTER TRACE. 19 25 WITH LOG. 0 0. , 25, 25.
state 0 255, :
[state] - 0 255. 1. , 255, .
:
RAISEERROR('Test', 20, 1);
Msg 102, 15, 1, 1
"".
DECLARE @err_message nvarchar(255);
SET @err_message = 'Test';
RAISEERROR(@err_message, 20, 1);
Msg 102, 15, 1, 3
"RAISEERROR".
. :.
THROW 50001, 'Test', 1;
Msg 50001, 16, 1, 1
SELECT @@VERSION :
Microsoft SQL Server 2016 (RTM-GDR) (KB3194716) - 13.0.1722.0 (X64) 26 2016 13:17:23 Copyright (c) Microsoft Corporation Express Edition (64- ) Windows 8.1 Pro 6.3 (Build 9600:)
MSDN " SQL Server ( 2008 )", ββ October 19, 2016, SQL Server .
?