title: 'an expression of non boolean type specified' in CASE WHEN
body: <p>Given this T-SQL code:</p>
  
  <pre><code>SELECT CASE 
           WHEN ( Cast (CASE 
                          WHEN Isnull(bpe.new, 0) = 0 
                               AND Isnull(bpe.regular, 0) = 0 
                               AND Isnull(bpe.bargain, 0) = 0 THEN 0 
                          ELSE 1 
                        END AS BIT) 
                  AND @siteID IS NULL 
                   OR bpe.siteid = @siteID ) THEN 1 
           ELSE 0 
         END AS SiteHasBrandException 
  FROM   brandpromoexceptions AS bpe 
  </code></pre>
  
  <p>I get the error message:</p>
  
  <blockquote>
    <p>an expression of non boolean type specified in the context where a condition is expected TSQL</p>
  </blockquote>
  
  <p>Why is that?</p>