Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I want to multiply order_price

Status
Not open for further replies.

technoknow

Technical User
Apr 19, 2002
121
US
Hi,
I want to multiply order_price * quantity for each record in a recordset
and them get the sum of all records.

Here is my query.
<% strQuery =&quot;Select order_price, orderid, quantity &quot; & _
&quot;FROM orderline &quot; & _
&quot;WHERE orderid = &quot; & intOrderID %>
Here is how I'm trying to multiply the records and get the sum in sglSubTotal
<% Do While Not rsOrderTotal.EOF %>
<% sglSubTotal =rsOrderTotal(&quot;ORDER_PRICE&quot;) * rsOrderTotal(&quot;QUANTITY&quot;) %>
<% rsOrderTotal.MoveNext %>
<% Loop %>
Can someone lead me in the right direction? Do I need to make a static
variable?
Thanks,
Jim
 
The code in the above message sets sglSubTotal to Order_Price * Quantity for each record but what do I need to do to get the total of all of the records?
Jim
 
You'd probably want to make a SQL query requesting the SUM of that column for those records matching your selection criteria.

This is an ASP question, or to be honest an Access or SQL Server question (depending on your database). This isn't a VBScript question. Have you asked in those forums?
 
Dilettante,
thanks for your reply. You're right I really should have posted this in a different forum. I've figured out my answer. It seems that I usually have better luck figuring something out after I post a question. I guess that writing it down makes me think it through more clearly.
In case anyone follows this post here is what I did:
Here is my query.
<% strQuery =&quot;Select order_price * quantity AS Sub_Total, orderid &quot; & _
&quot;FROM orderline &quot; & _
&quot;WHERE orderid = &quot; & intOrderID %>
Here is how I put the sum of order_price into the variable sglSubTotal
<% Do While Not rsOrderTotal.EOF %>
<% If sglSubTotal = 0 Then %>
<% sglSubTotal =rsOrderTotal(&quot;Sub_Total&quot;) %>
<% Else %>
<% sglSubTotal = sglSubTotal + rsOrderTotal(&quot;Sub_Total&quot;) %>
<% End If %>
<% rsOrderTotal.MoveNext %>
<% Loop %>
Thanks,
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top