title: Subquery Caching with Sql Server 2008
body: <p>I am creating a stored procedure with Sql Server 2008 which will return 2 result sets. The first query returns a result set that I would like to resuse as in the second query as a subquery (see example below). However, since the first query and the subquery essentially return the same data, I was wondering if there is some caching meachanism that I can use. Is it possible to do that? I am trying to optimize for performance.</p>
  
  <pre><code>SELECT * 
  FROM   Employees
  WHERE  BossId = 1
  
  SELECT * 
  FROM   CostCenters
  WHERE  EmployeeId IN (
      SELECT EmployeeId 
      FROM   Employees
      WHERE  BossId = 1
  )
  </code></pre>
  
  <p>P.S. The example is a simplified problem. </p>