title: Using WITH in subquery (MS SQL)
body: <p>I'm trying to perform some recursion inside a subquery, but I don't seem to be able to use <code>WITH</code> - Have I missed something or is there a workaround perhaps?</p>
  
  <pre><code>WHERE swn.stocknode_id in 
  (
      WITH Hierachy(stocknode_id, short_desc, PARENTNODE_ID, level)
  
      AS
  
      (
          SELECT 
              a.stocknode_id,
              0 AS level
  
          FROM stock_website_node AS a  
  
          WHERE a.short_desc = 'XXXXXXXX'
          AND a.PARENTNODE_ID = 0
  
          UNION ALL
  
          SELECT 
              a.stocknode_id,
              ch.level + 1
  
          FROM stock_website_node AS a
  
          INNER JOIN Hierachy ch
          ON a.PARENTNODE_ID = ch.stocknode_id
      )
  
      SELECT 
          stocknode_id
  
      FROM Hierachy
  
      WHERE level &gt; 0
  ) 
  </code></pre>
  
  <p>I'm met with:</p>
  
  <p><code>Incorrect syntax near the keyword 'WITH'.</code></p>