stored procedure syntax

I am using ASP/VBScript and MS SQL 2008

I am passing the following values to an ASP page:

<%=Request("itemid")%>  --- the values passed in this example are :
<%=Request("amount")%> --- the values passed in this example are:

Then I create a recordset that will return records based on the 'itemids' passed on to it

-- Recordset --

<%
Dim BillingItems__MMColParam
BillingItems__MMColParam = "0"
If (Request("itemid") <> "") Then 
  BillingItems__MMColParam = Request("itemid")
End If
%>
<%
Dim BillingItems
Dim BillingItems_cmd
Dim BillingItems_numRows

Set BillingItems_cmd = Server.CreateObject ("ADODB.Command")
BillingItems_cmd.ActiveConnection = MM_eimmigration_STRING
BillingItems_cmd.CommandText = "SELECT Id, CaseId, ItemId, ItemDesc, ItemlongDec, UnitCost, Qty, PmtRecd,((UnitCost * Qty)-PmtRecd) AS Balance FROM BillingLines WHERE id in (?) AND ((UnitCost * Qty)-PmtRecd) <>0" 
BillingItems_cmd.Prepared = true
BillingItems_cmd.Parameters.Append BillingItems_cmd.CreateParameter("param1", 5, 1, -1, BillingItems__MMColParam) ' adDouble

Set BillingItems = BillingItems_cmd.Execute
BillingItems_numRows = 0
%>

Open in new window


Then I go through all the values of the recordset that is returned to insert into a table, looping through them:


-- Stored procedure --

<%while not BillingItems.eof
'execute SP
%>

<%

Dim AddPaymentLines__Caseid
AddPaymentLines__Caseid = "0"
if(BillingItems("CaseId") <> "") then AddPaymentLines__Caseid = BillingItems("CaseId")

Dim AddPaymentLines__BillsMainId
AddPaymentLines__BillsMainId = "0"
if(Session("PaymentId") <> "") then AddPaymentLines__BillsMainId = rs_topbillpymnt("MainPaymntId")

Dim AddPaymentLines__EntryBy
AddPaymentLines__EntryBy = "0"
if(Session("UserId") <> "") then AddPaymentLines__EntryBy = Session("UserId")

Dim AddPaymentLines__ItemId
AddPaymentLines__ItemId = "0"
if(BillingItems("Id") <> "") then AddPaymentLines__ItemId = BillingItems("Id")

Dim AddPaymentLines__ItemDesc
AddPaymentLines__ItemDesc = "0"
if(BillingItems("ItemDesc") <> "") then AddPaymentLines__ItemDesc = BillingItems("ItemDesc")

Dim AddPaymentLines__PmtRecd
AddPaymentLines__PmtRecd = "0"
if(BillingItems("PmtRecd") <> "") then AddPaymentLines__PmtRecd = BillingItems("PmtRecd")

Dim AddPaymentLines__Balance
AddPaymentLines__Balance = "0"
if(BillingItems("Balance") <> "") then AddPaymentLines__Balance = BillingItems("Balance")

Dim AddPaymentLines__UnitCost
AddPaymentLines__UnitCost = "0"
if(BillingItems("UnitCost") <> "") then AddPaymentLines__UnitCost = BillingItems("UnitCost")

%>

<%

set AddPaymentLines = Server.CreateObject("ADODB.Command")
AddPaymentLines.ActiveConnection = MM_eimmigration_STRING
AddPaymentLines.CommandText = "dbo.BDOTAddPaymentLines"
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@RETURN_VALUE", 3, 4)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@Caseid", 3, 1,4,AddPaymentLines__Caseid)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@BillsMainId", 3, 1,4,AddPaymentLines__BillsMainId)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@EntryBy", 3, 1,4,AddPaymentLines__EntryBy)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@ItemId", 3, 1,4,AddPaymentLines__ItemId)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@ItemDesc", 200, 1,250,AddPaymentLines__ItemDesc)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@PmtRecd", 6, 1,8,AddPaymentLines__PmtRecd)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@Balance", 6, 1,8,AddPaymentLines__Balance)
AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@UnitCost", 6, 1,8,AddPaymentLines__UnitCost)
AddPaymentLines.CommandType = 4
AddPaymentLines.CommandTimeout = 0
AddPaymentLines.Prepared = true
AddPaymentLines.Execute()

%>

<%
BillingItems.movenext
wend
%>

Open in new window

--------------------------

This is all good, the SP works fine, the problem is that the 'amount' is not being inserted because I don't have a way of inserting it by using the stored procedure, so it inserts all the information correctly, but the amount is left at '0', and I need to loop the amount as well, so that when it inserts the first row it inserts also the first amount, then the next row, next amount.

How can I do this ?
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AleksAuthor Commented:
I tried replacing the value of the 'Paymntrecv' to be:

Dim AddPaymentLines__PmtRecd
AddPaymentLines__PmtRecd = "0"
if(Request("amount") <> "") then AddPaymentLines__PmtRecd = Request("amount")

but of course, amount is :  15,50  because its not looping the values.

BTW, seems like I forgot to enter the values at the beginning:

Itemids = 4506, 4508

Amounts = 15, 50
0
AleksAuthor Commented:
I thought adding the whole page would be easier. The values being passed are:

'Itemid' and 'amount'

I use the itemid's to filter the "BillingItems" recordset and return the details of each item, but I can't tie the 'amount' to each item in that recordset by simply using the id to filter them out, is there a way to add the 'amount' to the records returned by the recordset ?  This would solve the issue and I would not have to worry about modifying the SP.

Right now the recordset returns:

paymntid, caseid, entryby, etc ...

Would be great to append the amount at the end so that it returns something like:

paymntid, caseid, entryby, etc ..., amount

next record ...

This way I can take the value from the recordset and use my stored procedure.
page.txt
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Unless you are allowing people to pay a portion of what is owed, the rule of thumb is to never pass the price through the form to pay.    The only thing I would pass is the item number and qty.    Then in your SP, you can create a look up for the item id and grab the price that way.  Or create a recordset before the SP is called to look up the price.  


item_id = request.form("item")
qty        = request.form("qty")

' --- create recordset of items you sell called rsItems where the item's id is = to item_id
selling_price = rs("item_price")

' -- now update your SP
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

AleksAuthor Commented:
I am allowing people to pay for a portion of what is paid, hence the way it should work. If someone has a way of appending the amount it would be greatly appreciated.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
are you trying to do this without modifying the stored procedure? if so, you would need to break out the amounts into an array, loop through them, then update the records that you just inserted with the correct amount. modifying the SP to accept another parameter (amount) would make things much more simpler. Let me know which direction you'd like to go in and I'll get you something to work off of in a little bit
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
so we can take the same approach here that we took in the other question, split the IDs into an array and loop through them and insert the data into the database.

try this:

dim itemIDs : itemIDs = Request("itemID")
dim amounts : amounts = Request("amount")
dim arrItemID : arrItemID = Split( itemIDs, "," )
dim arrAmount : arrAmount = Split( amounts, "," )

<%while not BillingItems.eof
'execute SP

	for counter = 0 to UBound( arrItemID )

	Dim AddPaymentLines__Caseid
	AddPaymentLines__Caseid = "0"
	if(BillingItems("CaseId") <> "") then AddPaymentLines__Caseid = BillingItems("CaseId")

	Dim AddPaymentLines__BillsMainId
	AddPaymentLines__BillsMainId = "0"
	if(Session("PaymentId") <> "") then AddPaymentLines__BillsMainId = rs_topbillpymnt("MainPaymntId")

	Dim AddPaymentLines__EntryBy
	AddPaymentLines__EntryBy = "0"
	if(Session("UserId") <> "") then AddPaymentLines__EntryBy = Session("UserId")

	Dim AddPaymentLines__ItemId
	AddPaymentLines__ItemId = "0"
	if(arrItemID( counter ) <> "") then AddPaymentLines__ItemId = arrItemID( counter )

	Dim AddPaymentLines__ItemDesc
	AddPaymentLines__ItemDesc = "0"
	if(BillingItems("ItemDesc") <> "") then AddPaymentLines__ItemDesc = BillingItems("ItemDesc")

	Dim AddPaymentLines__PmtRecd
	AddPaymentLines__PmtRecd = "0"
	if(arrAmount( counter ) <> "") then AddPaymentLines__PmtRecd = arrAmount( counter )

	Dim AddPaymentLines__Balance
	AddPaymentLines__Balance = "0"
	if(BillingItems("Balance") <> "") then AddPaymentLines__Balance = BillingItems("Balance")

	Dim AddPaymentLines__UnitCost
	AddPaymentLines__UnitCost = "0"
	if(BillingItems("UnitCost") <> "") then AddPaymentLines__UnitCost = BillingItems("UnitCost")

	set AddPaymentLines = Server.CreateObject("ADODB.Command")
	AddPaymentLines.ActiveConnection = MM_eimmigration_STRING
	AddPaymentLines.CommandText = "dbo.BDOTAddPaymentLines"
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@RETURN_VALUE", 3, 4)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@Caseid", 3, 1,4,AddPaymentLines__Caseid)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@BillsMainId", 3, 1,4,AddPaymentLines__BillsMainId)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@EntryBy", 3, 1,4,AddPaymentLines__EntryBy)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@ItemId", 3, 1,4,AddPaymentLines__ItemId)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@ItemDesc", 200, 1,250,AddPaymentLines__ItemDesc)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@PmtRecd", 6, 1,8,AddPaymentLines__PmtRecd)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@Balance", 6, 1,8,AddPaymentLines__Balance)
	AddPaymentLines.Parameters.Append AddPaymentLines.CreateParameter("@UnitCost", 6, 1,8,AddPaymentLines__UnitCost)
	AddPaymentLines.CommandType = 4
	AddPaymentLines.CommandTimeout = 0
	AddPaymentLines.Prepared = true
	AddPaymentLines.Execute()

BillingItems.movenext
wend
%>

Open in new window


I put each itemID in the AddPaymentLines__ItemId variable, and each amount in the AddPaymentLines__PmtRecd variables, if they belong elsewhere, just change the variables. This should get you going in the direction you need to be going without changing the SP.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
any luck with this?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.