title: Invalid column name error in WHERE clause, column selected with CASE
body: <p>I have a (rather complicated) SQL statement where I select data from lots of different  tables, and to cope with a bad legacy data structure, I have a couple of custom columns that get their values based on values from other columns. I have currently solved this with <code>CASE</code> statements:</p>
  
  <pre><code> SELECT
       ...,
       CASE channel
           WHEN 1 THEN channel_1
           WHEN 2 THEN channel_2
           ...
           ELSE 0
       END AS ChannelValue,
       CASE channelu
           WHEN 1 THEN channelu_1
           WHEN 2 THEN channelu_2
           ...
           ELSE '0'
       END AS ChannelWithUnit,
       ...
   FROM 
       ... 
   --rest of statement continues with multiple joins and where/and clauses...
  </code></pre>
  
  <p>I get all the results I expect when executing the query in MS SQL Server Management Studio, and the column names are listed as I have specified in my <code>AS</code> clauses. However, for some reason I'm not allowed to use the conditional values in a <code>WHERE</code> statement. If I add</p>
  
  <pre><code>AND ChannelValue &gt; Limit * p.Percentage / 100
  </code></pre>
  
  <p>at the end of the query, I get an error on that line saying </p>
  
  <blockquote>
    <p>Msg 207, Level 16, State 1, Line 152<br>
    Invalid column name 'ChannelValue'</p>
  </blockquote>
  
  <p>Why is this not allowed? What should I do instead?</p>