Solved

Update current balance sql

Posted on 2014-10-21
3
180 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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Date on a table 16 43
Html split(text) 2 44
SQL Query Works in SQL 2008 & 2012 But Not SQL 2016 15 95
TSQL remove duplicates from different columns 14 48
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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