Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

stored procedure syntax

Posted on 2014-10-21
8
Medium Priority
?
170 Views
Last Modified: 2014-11-06
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 ?
0
Comment
Question by:Aleks
  • 3
  • 3
7 Comments
 

Author Comment

by:Aleks
ID: 40394327
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
 

Author Comment

by:Aleks
ID: 40394335
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
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 668 total points
ID: 40394380
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:Aleks
ID: 40394534
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
 
LVL 34

Expert Comment

by:Big Monty
ID: 40394830
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
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1332 total points
ID: 40396102
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
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1332 total points
ID: 40402724
any luck with this?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

581 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