Average value of a DBRW column

  • Thread starter Thread starter Mick
  • Start date Start date
M

Mick

Hi, need a little help on this one please.
I have an ASP that displays the results of an Access database. I have a
column of numbers that I add up with
<%
if FP_FieldVal(fp_rs,"hireitem5") = dthireitem then
If isnumeric (dtresourceid5) then
dtresourceid55 = dtresourceid55 + CDbl (dtresourceid5)

Else
'Give an error message
End if
End if
%>

What I would like to do, is take the result number in this case
dtresourceid55 and find the average of the number of records displayed.
So if there are 20 results displayed and the total of dtresourceid55 is 60,
I would like to work out and display automatically the average (3). Thanks
for your help
 
Set up a counter for each dtresourceid55 found as say Cntdtresource
- note you need to check for empty field for dtresourceid5 to prevent errors on isnumeric(dtresourceid5)

<%
Cntdtresource=0
dtresourceid55=0
' both of the above need to be outside your loop, say at top of page
%>

<%
'below is in your record set loop
If FP_FieldVal(fp_rs,"hireitem5") = dthireitem AND Len(dtresourceid5)>0 Then
If isnumeric (dtresourceid5) Then
dtresourceid55 = dtresourceid55 + CDbl (dtresourceid5)
Cntdtresource=Cntdtresource+1 'increment counter
Else
'Give an error message
End If
End If
%>

<%
'below needs to be after your loop
If Cntdtresource>0 Then
Avgdtresource=Round(dtresourceid55/Cntdtresource,2)
Else
Avgdtresource=0
End if
%>


--




| Hi, need a little help on this one please.
| I have an ASP that displays the results of an Access database. I have a
| column of numbers that I add up with
| <%
| if FP_FieldVal(fp_rs,"hireitem5") = dthireitem then
| If isnumeric (dtresourceid5) then
| dtresourceid55 = dtresourceid55 + CDbl (dtresourceid5)
|
| Else
| 'Give an error message
| End if
| End if
| %>
|
| What I would like to do, is take the result number in this case
| dtresourceid55 and find the average of the number of records displayed.
| So if there are 20 results displayed and the total of dtresourceid55 is 60,
| I would like to work out and display automatically the average (3). Thanks
| for your help
 
Back
Top