Result set calulation

Associate
Joined
21 Feb 2004
Posts
886
Hi, I’ve got a result set in asp which is being looped though until end of file. It is being displayed in a table. What I want to achieve is adding up all of one column so I have a total of a particular column. I can’t seem to figure it out, here is my code:

Code:
<%while not adoRS.EOF

dim parttotal
parttotal = (adoRS.fields(2).value * adoRS.fields(3).value)

%>	  
      <tr>
        <td align="center"><%=adoRS.fields(0).value%></td>
        <td align="left">&nbsp;<%=adoRS.fields(1).value%></td>
        <td align="center"><%=adoRS.fields(2).value%></td>
        <td align="center"><%=adoRS.fields(3).value%></td>
        <td align="center"><%=parttotal%></td>
      </tr>
<%
	adoRS.MoveNext
	
	wend%>


Basically, there’s going to be multiple "parttotal" and I want to add all these up for the amount I have.

Please could some one help? Thank you in advance.
 
Associate
Joined
1 Feb 2006
Posts
1,868
Location
Reading
Why not use a variable outside the while loop scope that stores the full total and each loop add the part total to the full total.

Code:
parttotal = (adoRS.fields(2).value * adoRS.fields(3).value)
fulltotal = fulltotal + parttotal

Once the recordset has reached the end fulltotal will hold the sum of all part totals.
 
Back
Top Bottom