title: SumIF in SQL Access
body: <p>Hello I am a beginner in VBA/SQL.    I have 2 tables [Broker] and [OPT]. [Broker] have 2 fields <code>BRKR_CODE, Status</code> and [OPT] Have 5 fields <code>BRKR1, BRKR2, Date, COM_BRK1, COM_BRKR2</code></p>
  
  <p><code>OPT.BRKR1</code> and <code>OPT.BRKR2</code> are linked to <code>Broker.BRKR_CODE</code> and can be equal.</p>
  
  <p>I want to write this query.... If <code>Broker.Status="Active"</code> then Select <code>Broker.BRKR_CODE</code>
  and then for each <code>Broker.BRKR_CODE</code> (for example "CB") do the Sum of <code>OPT.COM_BRKR1</code> when <code>OPT.BRKR1="CB"</code> + Sum of <code>OPT.COM_BRKR2</code> when <code>OPT.BRKR2="CB"</code></p>
  
  <p>I wrote this code.... but it doesnot work at all... as I said I am a newbie...</p>
  
  <pre><code>    SELECT IIF(Broker.Status="Active",Broker.BRKR_CODE), Sum(OPT.COM_BRKR1)+ Sum(OPT.COM_BRKR2) AS OPT_Tot
  
  FROM Broker INNER JOIN OPT ON (Broker.BRKR_CODE = OPT.BRKR2) AND (Broker.BRKR_CODE = OPT.BRKR1)
  
  GROUP BY Broker.BRKR_CODE;
  </code></pre>
  
  <p>Thanks a lot</p>