Question : Avg function display and sort

I have a field I am trying to display an average of. I am having two issues with the display:

#1: I only want 2 decimal places to display for calculation AvgLibFTE
#2: I want to be able to sort by the AvgLibFTE

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
<% 
	'---Create recordset 

	Dim sql, objRS, s_name, s_order, s_next_order
	 
sql = "SELECT Complexity, count(*) as ComplexityCount, " & _ 
        "Avg( LibFTE ) as AvgLibFTE " & _
 	"FROM tblGeneral INNER JOIN tblStaff ON tblGeneral.ChartID= tblStaff.ChartID " & _
         "WHERE AllHCF = 'YES' " & _
		"GROUP BY Complexity "
	
	s_name =  Request.querystring("sort")
	
	If Request.Querystring("order") = "1" Then
		s_order = "ASC"
		s_next_order = 0
	Else
		s_order = "DESC"
		s_next_order = 1
	End If
	
	Select Case s_name
		Case "Complexity"
			sql = sql + "ORDER BY Complexity " + s_order + " "
		Case "ComplexityCount"
			sql = sql + "ORDER BY Count(*) " + s_order + " "
		Case "AvgLibFTE"
			sql = sql + "ORDER BY Avg( LibFTE ) " + s_order + " "
	End Select

	Set objRS = Server.CreateObject("ADODB.Recordset") 
	objRS.Open sql, objConn 




%>


<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

		<title><%=title%></title>
		
		<link rel=stylesheet type="text/css" href="/CodeReuse/style.css">
	</head>

	<body>
	
		<h2 align="left"><font face="Arial" size="4"><%=title%></font></h2>
		<p>* Indicates a consolidated facility, no separate complexity level assigned.<br>
		Includes only <i>All HCF</i> designated facilities.
		</p>


		<%
		   	If (objRS.EOF) Then
		   		'---NO ROWS TO DISPLAY
		   	Else
		   		'---DISPLAY ROWS IN A HTML FORMATTED TABLE
		%>
			<table class="CCTable" cellspacing='0' border='1' cellpadding='5' width='400px>
				<TR style='background-color: white;'>
				<TH class="CCTable" scope='col' width='150px'><font size='1' color='blue'><a href='?sort=Complexity&order=<%=s_next_order%>'><font color='blue'><b>Complexity<br>Level</b></font></a></th>
				<TH class="CCTable" scope='col' width='150px'><font size='1' color='blue'><a href='?sort=ComplexityCount&order=<%=s_next_order%>'><b># of Medical<br>Centers</b></a></font></th>
				<TH class="CCTable" scope='col' width='150px'><font size='1' color='blue'><a href='?sort=avgLibFTE&order=<%=s_next_order%>'><b>Average # of<br>FTE</b></a></font></th></TR>
		<%                             
		
			Dim r_complexity, r_complexity_count, r_avgLibFTE
		         
		  	Do While (NOT objRS.EOF)
				r_complexity = Trim( objRS("Complexity") )
				r_complexity_count = Trim( objRS("ComplexityCount") )
				r_complexity_count = Trim( objRS("ComplexityCount") )
				r_avgLibFTE = Trim( objRS("avgLibFTE") )		                                         
		%>
				<tr>
					<td class="CCTable"><%=r_complexity%>&nbsp;</td>
					<td class="CCTable" align="center"><%=r_complexity_count%>&nbsp;</td>
					<td class="CCTable" align="center"><%=r_avgLibFTE%>&nbsp;</td>
				</tr>
		<%                                      
				'---MOVE TO NEXT ROW   
				objRS.MoveNext()
			Loop  
		%>
		        </table>
		<%                              
		 	End If
		       
		         
			'---CLEAN UP
			objRS.Close
			Set objRS= Nothing
		%>
	</body>
</html>

Answer : Avg function display and sort


For your rounding of Avg( LibFTE ) use this


round(Avg( LibFTE ),2)
Random Solutions  
 
programming4us programming4us