title: How do I create a Stored Procedure if it doesn't exist in TSQL
body: <p>I have tried this:</p>
  
  <pre><code>if object_id('a_proc22') is not null
  CREATE PROCEDURE a_proc22 AS SELECT 1
  go
  </code></pre>
  
  <p>but it gives me a syntax error.</p>
  
  <p>But this seemed to compile:</p>
  
  <pre><code>if object_id('a_proc22') is not null
  EXEC('CREATE PROCEDURE a_proc22 AS SELECT 1')
  go
  </code></pre>
  
  <p>Why is the first one incorrect?</p>