title: SQL Error. Get the last particular fee charged on every type of account
body: <p>I have different types of accounts in my dataset, so for each Acct I want to get the last TransProcessDate with a particular code and Narrative. (Basically show the date when the last particular fee was charged)</p>
  <p>I have here given an example for S8 type account, but this code is throwing an error:</p>
  <blockquote>
  <p>&quot;Subquery returned more than 1 value. This is not permitted when the
  subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used as
  an expression.&quot;</p>
  </blockquote>
  <p>What am I doing wrong? Please help. Thanks</p>
  <pre><code>CASE 
      WHEN acct = 'S8' 
          THEN (SELECT DISTINCT transprocessdate 
                FROM qpcureporting.dbo.acctran t1 
                INNER JOIN 
                    (SELECT MAX(transprocessdate) maxdate, id, transcode 
                     FROM qpcureporting.dbo.acctran AT 
                     GROUP BY id, transcode) t2 ON t1.id = t2.id 
                                                AND t1.transprocessdate = t2.maxdate 
                                                AND t1.transcode = ('67') 
                                                AND transnarrative = 'WITHDRAWAL FEES') 
      WHEN acct = 'S6'   
           ....
   ....
  </code></pre>