title: Arithmetic overflow error converting expression to data type money
body: <p>I have following query, where datatype of accc_no is varchar, wthdrl_amt  is money, sav_amt is money, trxn_id  is bigint.</p>
  
  <pre><code>DECLARE @acc_no NVARCHAR(MAX) = N''
  DECLARE @symbol NVARCHAR(MAX) = N''
  DECLARE @loop int = 0
  DECLARE @loop2 int = 0
  
  SELECT @symbol += N'' + acc_no + ',' FROM sav_transaction GROUP BY acc_no HAVING (SUM(sav_amt)&lt;SUM(wthdrl_amt))
  IF LEN(@symbol) &gt; 1
  BEGIN
      WHILE @loop &lt; LEN(@symbol)
      BEGIN
          SET @loop2 = CHARINDEX(',', @symbol ,@loop)
          SET @acc_no = SUBSTRING(@symbol, @loop, @loop2-@loop)
  
          UPDATE sav_transaction
          SET wthdrl_amt = wthdrl_amt-(SELECT ABS(SUM(sav_amt)  - SUM(wthdrl_amt))
          FROM sav_transaction WHERE acc_no = @acc_no)
          WHERE acc_no = @acc_no AND trxn_id = (SELECT MAX(trxn_id) FROM sav_transaction WHERE acc_no = @acc_no )
      END
      SET @loop = @loop2 +1
  END
  </code></pre>
  
  <p>But when I run this, I get error :</p>
  
  <pre><code>Msg 8115, Level 16, State 2, Line 15
  Arithmetic overflow error converting expression to data type money.
  The statement has been terminated.
  </code></pre>
  
  <p>I have used the field with same data type. But couldn't find the error.</p>