title: SQL SUM() function always returns 0
body: <p>I'm executing this statement on an ASP.NET platform with SQL Server </p>
  
  <pre><code>SELECT id, size, color, 
          SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN stock ELSE 0 END) 
          + SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN incoming ELSE 0 END) 
          - SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN outgoing ELSE 0 END) 
      AS Total 
  FROM stocks 
  GROUP BY id, size, color
  </code></pre>
  
  <p>And this is the code I'm using to retrieve the obtained values</p>
  
  <pre><code>For Each rowStock In TableStocks.Rows
      Dim product As New ProductInfo
      With product
          .id = rowStock("id")
          .size = rowStock("size")
          .color = rowStock("color")
          .stock = rowStock("Total")
      End With
  Next
  </code></pre>
  
  <p><code>id</code>, <code>size</code> and <code>color</code> values are correct, but the result of the <code>SUM</code> function is always 0. If I run the query on the SQL Server management it works fine.</p>
  
  <p>I've tried changing</p>
  
  <pre><code>.stock = rowStock(3)
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>.stock = rowStock("Total")
  </code></pre>
  
  <p>but I'm getting the same result. I can't figure what I'm missing.</p>