Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Update current balance sql

I will check on this post tonight. Its the last portion of the code I have been working on, this is what I got so far:

---

<%
'-- create connection object and establish a connection to the database
set conn = Server.CreateObject("ADODB.Connection")
conn.Open MM_eimmigration_STRING

id = request.form("id")
amounts = request.form("amount")

arrItemIDs = Split( itemIDs, "," )
arrAmounts = Split( amounts, "," )

'-- now loop through the array and insert into the database
for counter = 0 to UBound( arrItemIDs )
      if arrItemIDs( counter ) <> "" then       '-- you also may want to check to make sure it's an numerical value
                        sql = "Update BillPaymntsRecvd SET PmtRecd  = ( )"
            conn.Execute( sql )            '-- assumes you have a connection object created and connected to the database
      end if
next

if conn.State <> 0 then conn.Close
set conn = nothing
      
%>

-------

This goes through a comma separated array. What it should do is take the current value of the 'balance' and add the 'amount' to it, then go to the next record and so on.

In other words:

The table name is : BillingLines
The id= is the key we will use to go through the records

I need to do the following:  Update BillingLines SET PmtRecd = PmtRecd + arrAmounts( counter )

So it will add the amount paid to the current payment received. I just need help with the SQL portion of the code.
Avatar of ste5an
ste5an
Flag of Germany image

You need also to ensure that both arrays have the same length. Then the simple solution could be:

if arrItemIDs( counter ) <> "" then
    sql = "Update BillPaymntsRecvd SET PmtRecd  = PmtRecd + " & arrAmounts(counter) & " where ID = " & arrItemIDs(counter)
  conn.Execute( sql )
end if

Open in new window


Caveat: this may allow SQL injection, when you don't check the content of your arrays. The both must only contain numbers.
A better approach would be using a parameterized query.
ASKER CERTIFIED SOLUTION
Avatar of Haris Dulic
Haris Dulic
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Thanks !