title: SQL only a throw inside if statement
body: <p>I am adding some validation to a couple of stored procedures and need to check if some of the variables are not null (they are populated earlier in the stored procedure).</p>
  
  <p>I have been trying to add a "throw" inside an if statement like below:</p>
  
  <pre><code>IF (@val is null)
  BEGIN
      THROW 50001, 'Custom text', 1
  END
  </code></pre>
  
  <p>This causes a syntax error on the "throw" as it is looking for other code inside the if statement prior to the throw but I only need it to perform the throw inside the if statement.</p>
  
  <p>I need to keep the stored procedure as light as possible to keep it as fast as possible to execute.</p>
  
  <p>Does anyone have any ideas?</p>