title: CONDITIONAL SUM T-SQL
body: <p>I have a table in this format</p>
  
  <pre><code>COL1 COL2 COL3
  A    NULL  4
  A    NULL  4
  A    VAL1  4
  A    VAL2  4
  A    VAL3  4
  B    NULL  5
  B    VAL1  6
  </code></pre>
  
  <p>I need to bring out the output as follows:</p>
  
  <pre><code>COL1 TOTAL VALID
  A    20     12
  B    11     6
  </code></pre>
  
  <p>My Question is, how do I get the 'VALID' column - it should do sum of col3 only if col2 is not null.</p>
  
  <p>I was able to get the 'TOTAL' field correctly using SUM and group by clauses. But how do I compute the 'VALID' column? </p>
  
  <p>Any ideas?
  Thanks a lot!</p>