title: Set MS Sql result in variable and reuse it
body: <p>Currently my code is something like this.</p>
  
  <pre><code>select * 
  from tblReq 
  where ReqID in (select ReqID from tblLog where LogDate &gt;= '2015/04/01' and LogDate &lt; '2015/05/31')
  </code></pre>
  
  <p>Just wondering how actually the database find the result for this query? Is it re-run every time it ran in sub-query? And is there any script where I can store the list of result in some variable and able to use it back? (below code)</p>
  
  <pre><code>select @logs = tblLog.ReqID from tblLog where tblLog.LogDate &gt;= '2015/04/01' and tblLog.LogDate &lt; '2015/05/31'  
  select * from tblReq where ReqID in (@logs)
  </code></pre>