?
Solved

Update current balance sql

Posted on 2014-10-21
3
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

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 2000 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

741 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