title: How to use Common Table Expression with parameters?
body: <p>I have a stored procedure with 2 CTEs. The second CTE has a parameter </p>
  
  <pre><code>WITH path_sequences
  AS
  (
  
  ),
  WITH categories
  AS
  (
      ... WHERE CategoryId = @CategoryId 
      // I dont know how to get this initial parameter inside the CTE 
  )
  
  SELECT * FROM path_sequences p
  JOIN categories c
  ON p.CategoryId = c.CategoryId
  </code></pre>
  
  <p>The initial parameter that I need to get inside the second TCE is <strong>p.CategoryId</strong>. How do I do that without having to create another stored procedure to contain the second CTE?</p>
  
  <p>Thanks for helping</p>