title: SQL Server 2005 Setting a variable to the result of a select query
body: <p>How do I set a variable to the result of select query without using a stored procedure? </p>
  
  <hr>
  
  <p>I want to do something like:
  OOdate DATETIME</p>
  
  <pre><code>SET OOdate = Select OO.Date 
  FROM OLAP.OutageHours as OO
  WHERE OO.OutageID = 1
  </code></pre>
  
  <p>Then I want to use OOdate in this query:</p>
  
  <pre><code>SELECT COUNT(FF.HALID) from Outages.FaultsInOutages as OFIO
  INNER join Faults.Faults as FF ON FF.HALID = OFIO.HALID
  WHERE CONVERT(VARCHAR(10),OO.Date,126) = CONVERT(VARCHAR(10),FF.FaultDate,126)) 
  AND
  OFIO.OutageID = 1
  </code></pre>