title: TSQL use inner select result for outer FROM
body: <p>I have a query that looks like the following:</p>
  
  <pre><code>    A.[approvalDate],
      A.[locationID],
      B.[FirstName] + ' ' + B.[LastName] AS nomineeName,
      B.[ntid] AS nomineeNTID,
      B.[qid] AS nomineeQID,
      B.[GeoLocationDesc] as locationName,
      C.[FirstName] + ' ' + C.[LastName] AS submitName,
      C.[ntid] AS submitNTID,
      C.[empID] submitEmpID,
      D.[categoryName],
      (
          SELECT G.[qid] FROM empowermentProxies AS G WHERE G.[proxy] = @QID
      ),
      E.[FirstName] + ' ' + E.[LastName] as behalfOf,
      E.[NTID] AS behalfOfNTID
  FROM   empowermentSubmissions AS A
      INNER JOIN
      empTable AS B
      ON A.[nomineeQID] = B.[qid]
      LEFT OUTER JOIN
      empTable AS C
      ON A.[subQID] = C.[qid]
      INNER JOIN
      empowermentCategories AS D
      ON A.[categoryID] = D.[catID]
      JOIN empTable AS E
      ON E.[qid] = G.[qid]
  WHERE  @QID IN (SELECT proxy FROM empowermentProxies)
      AND A.[statusID] = 1
  FOR        XML PATH ('data'), TYPE, ELEMENTS, ROOT ('root');
  </code></pre>
  
  <p>I am trying to user the result of the inner select G.qid in the join statement but keep getting an error saying <code>G</code> isn't bound. </p>
  
  <p>Is this possible to do? There should only be 1 result returned from the inner select.</p>