title: SQL with clause in stored procedure
body: <p>Is it possible to define a with clause in a stored procedure and use it in if else statements because I always get an error?</p>
  
  <pre><code>BEGIN
      WITH Test (F, A) AS
      (
          SELECT FM.ID, FM.Name 
          FROM [Test.Abc] FM
          INNER JOIN [Organization] O on O.ABCID = FM.ID
      )
  
      IF(@var = 'case1')
      BEGIN
          SELECT * 
          FROM Test F
          WHERE NOT F.ID = 'someID'
      END
  </code></pre>
  
  <p>I always get an "Incorrect syntax" error before the if statement</p>
  
  <p>If I move the with clause into the if statement it works fine. But I need the with statement outside to reuse it in different if else statements.</p>