title: Select Statement with case and then gives error
body: <p>I have a complex stored procedure that has to return Sum of AmountSold as AmountSold and sum of AmountCollected as AmountCollected and also i have rows that has neither Sold nor collected and instead has Upgraded and UpgradedCollected colmns. Depending on the below conditions, that amount has to added into  Sold or collected or UpgradedCollected. I dont really understand the syntax error which says "Incorrect Syntax error near keyword as" and for "keyword then". What am i doing wrong here? Thank you in advance!</p>
  
  <p>In the first 2 if's, i have written different code assuming either of them should be correct. This is in SQL 05.  </p>
  
  <pre><code>Select sum(cast(RDC.AmountSold as numeric(10,2))) as AmountSold, 
  sum(cast(RDC.AmountCollected as numeric(10,2))) as AmountCollected,
  
  
  case when RDC.AmountUpgraded = RDC.AmountUpgradedCollected
          then sum(cast((AmountSold + RDC.AmountUpgraded)as numeric(10,2))) as AmountSold
          and sum(cast((AmountCollected + RDC.AmountUpgradedCollected)as numeric(10,2))) as AmountCollected
          else if RDC.AmountUpgraded &gt; RDC.AmountUpgradedCollected
          then AmountSold = AmountSold + RDC.AmountUpgraded 
          and AmountCollected = AmountCollected + RDC.AmountUpgradedCollected
          else
          then AmountSold = AmountSold + RDC.AmountUpgraded 
          and AmountCollected = AmountCollected + RDC.AmountUpgraded 
          and AmountUpgradedCollected = AmountUpgradedCollected + (RDC.AmountUpgradedCollected - RDC.AmountUpgraded)
          as AmountUpgradedCollected
  
  end
  </code></pre>