title: Query, subquery and using as variables from subquery
body: <p>Is it not possible to use the "as [item] and then use the item variable in the query.</p>
  
  <p>For example:</p>
  
  <pre><code>select c.category as [category],c.orderby as [CatOrder], m.masterno, m.master
  ,-- select OUT (select count(*) from    rentalitem       ri  with (nolock), 
              rentalitemstatus ris with (nolock), 
              rentalstatus     rs  with (nolock)
      where   ri.rentalitemid    = ris.rentalitemid
              and   ris.rentalstatusid = rs.rentalstatusid
              and   ri.masterid        = m.masterid
              and   rs.statustype     in ('OUT', 'INTRANSIT', 'ONTRUCK'))  as [qtyout] 
  ,-- select OWNED owned=
  (select top 1 mwq.qty                                           
      from    masterwhqty mwq                                              
      where   mwq.masterid    = m.masterid) 
  
  , -([owned]-[qtyout]) as [Variance]
  
  from master m 
      inner join category c on c.categoryid=m.categoryid and c.categoryid=@category
      inner join inventorydepartment d on c.inventorydepartment=@department
  </code></pre>
  
  <p>I cannot seem to use qtyout or owned when calculating variance. How can I do that?</p>