title: TSQL RaiseError incorrect syntax, following MSDN's guidelines
body: <p><a href="https://msdn.microsoft.com/en-us/library/ms178592.aspx" rel="noreferrer">MSDN</a> states the following syntax:</p>
  
  <pre><code>RAISERROR ( { msg_id | msg_str | @local_variable }  
  { ,severity ,state }  
  [ ,argument [ ,...n ] ] )  
  [ WITH option [ ,...n ] ] 
  </code></pre>
  
  <p>The <code>msg_str</code> expects a string up to 2047 characters but truncates longer strings. It also has the possibility of substituting parameters, which truncates the message further than the number of characters provided by the values:</p>
  
  <blockquote>
    <p>The error message can have a maximum of 2,047 characters. If the message contains 2,048 or more characters, only the first 2,044 are displayed and an ellipsis is added to indicate that the message has been truncated. Note that substitution parameters consume more characters than the output shows because of internal storage behavior. For example, the substitution parameter of %d with an assigned value of 2 actually produces one character in the message string but also internally takes up three additional characters of storage. This storage requirement decreases the number of available characters for message output.
    When msg_str is specified, RAISERROR raises an error message with an error number of 50000.</p>
  </blockquote>
  
  <p>The <code>severity</code> expects a number between 0 to 25, but corrects other numbers:</p>
  
  <blockquote>
    <p>Severity levels from 0 through 18 can be specified by any user. Severity levels from 19 through 25 can only be specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity levels from 19 through 25, the WITH LOG option is required. Severity levels less than 0 are interpreted as 0. Severity levels greater than 25 are interpreted as 25.</p>
  </blockquote>
  
  <p>The <code>state</code> expects values 0 to 255, but corrects subzero values:</p>
  
  <blockquote>
    <p>[state] is an integer from 0 through 255. Negative values default to 1. Values larger than 255 should not be used.</p>
  </blockquote>
  
  <hr>
  
  <h2>The issue</h2>
  
  <p>I get the following errors when I run these queries:</p>
  
  <pre><code>RAISEERROR('Test', 20, 1);
  </code></pre>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 1</p>
    
    <p>Incorrect syntax near 'Test'.</p>
  </blockquote>
  
  <hr>
  
  <pre><code>DECLARE @err_message nvarchar(255);
  SET @err_message = 'Test';
  RAISEERROR(@err_message, 20, 1);
  </code></pre>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 3</p>
    
    <p>Incorrect syntax near 'RAISEERROR'.</p>
  </blockquote>
  
  <hr>
  
  <p>I can execute various other queries just fine. E.g.:</p>
  
  <pre><code>THROW 50001, 'Test', 1;
  </code></pre>
  
  <blockquote>
    <p>Msg 50001, Level 16, State 1, Line 1</p>
    
    <p>Test</p>
  </blockquote>
  
  <hr>
  
  <h2>More info</h2>
  
  <p><code>SELECT @@VERSION</code> produces this:</p>
  
  <blockquote>
    <p>Microsoft SQL Server 2016 (RTM-GDR) (KB3194716) - 13.0.1722.0 (X64)   Sep 26 2016 13:17:23   Copyright (c) Microsoft Corporation  Express Edition (64-bit) on Windows 8.1 Pro 6.3  (Build 9600: ) </p>
  </blockquote>
  
  <p>And the MSDN syntax was for "<strong>SQL Server (starting with 2008)</strong>" and as of writing, the article was updated <code>October 19, 2016</code>, which is months after the release of the SQL Server version I'm running.</p>
  
  <p>What's going on here?</p>