Solved

Update current balance sql

Posted on 2014-10-21
3
169 Views
Last Modified: 2014-10-21
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.
0
Comment
Question by:amucinobluedot
3 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40395815
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.
0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
ID: 40395817
Here is the code:

sql = "Update BillPaymntsRecvd SET PmtRecd  =PmtRecd + " & arrAmounts( counter ) & " where id =" & arrItemIDs( counter )   

Open in new window


I assumed that the id in BillingLines is the arrItemIDs( counter ) , if thats not correct just change to appropriate ID field
0
 

Author Closing Comment

by:amucinobluedot
ID: 40396068
Thanks !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now