Solved

Update current balance sql

Posted on 2014-10-21
3
164 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 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks !
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
adding % symbol to a percentage - oracle query 16 39
query question 4 26
INNER JOIN ? 8 29
Pass through dll 2 33
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.…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

11 Experts available now in Live!

Get 1:1 Help Now