title: Case statement for different fields
body: <p>How could this be written?</p>
  
  <p>I need to check a few fields for various conditions to determine whether to mark a record Y or N for keeping it. (I'm trying to exclude some records from a report where certain criteria are not met.)</p>
  
  <p>I have tables aliased as ES, CQI, NA and CC in this example. So I need something like</p>
  
  <pre><code>CASE 
            WHEN SD.CType = N'ALT' AND ES.SERVICE = N'Alerts' THEN 'N'
            WHEN SD.CType = N'ALT' AND ES.SERVICE &lt;&gt; N'Alerts' THEN 'Y' 
            WHEN SD.CType &lt;&gt; N'ALT' AND ES.SERVICE &lt;&gt; N'Alerts' THEN 'Y' 
            WHEN SD.CType = 'BPY' AND CQI.PTYPE = 'BP' THEN 'Y'
            WHEN SD.CType &lt;&gt; 'BPY' AND CQI.PTYPE = 'BP' THEN 'N'
            WHEN SD.CType &lt;&gt; 'BPY' AND NA.BILL = 'Y' THEN 'Y' 
            WHEN SD.CType = 'BPY' AND NA.BILL = 'Y' THEN 'N'    
            WHEN SD.CType = 'LEN' AND CC.PTYPE &lt;&gt; 'CC' THEN 'Y'
            WHEN SD.CType = 'LEN' AND CC.PTYPE = 'CC' THEN 'N'
            ELSE 'Y'
         END    
            AS Keep
  </code></pre>
  
  <p>Basically these all include the SD.CType value, and then they get combined with values in 3 other fields. I could write a SELECT CASE statement in VB to do this, but I need this to run in SQL.</p>
  
  <p>I appreciate any suggestions..thanks!</p>