title: MS SQL: Nested Selects - Mysterious "Invalid column name" error
body: <p>When I run the following query against a MSSQL 2000</p>
  
  <pre><code>SELECT 
      DISTINCT(Email),
      (SELECT TOP 1 ActivityID
          FROM Activity aa, ActivityType tt 
          WHERE aa.ActivityTypeId = tt.ActivityTypeId 
              AND aa.ConsumerID = c.ConsumerID
              AND tt.ActivityType = 'Something_OptIn') optin,
      (SELECT TOP 1 ActivityID
          FROM Activity aa, ActivityType tt 
          WHERE aa.ActivityTypeId = tt.ActivityTypeId 
              AND aa.ConsumerID = c.ConsumerID
              AND tt.ActivityType = 'Something_OptOut') optout
  FROM
      Activity a,
      Consumer c,
      ActivityType t
  WHERE
      c.CountryID = '23'
      AND t.ActivityType = 'Something_Create'
      AND a.ActivityTypeId = t.ActivityTypeId
      AND c.ConsumerID = a.ConsumerID
      AND optin &gt; 1
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>Server: Msg 207, Level 16, State 3, Line 1
  Invalid column name 'optin'.
  </code></pre>
  
  <p>Why does this happen? I can't see why it would be invalid.</p>