61 lines
1.9 KiB
Plaintext
61 lines
1.9 KiB
Plaintext
<%
|
|
'Holds the original Number
|
|
Dim strNum
|
|
'Holds the new fixed number
|
|
Dim strNumFixed
|
|
'Get the ID usually an AutoNumber field,
|
|
' Just comment out or supply your own
|
|
strYourID = Request.QueryString("ID")
|
|
|
|
'Sets your connection, I used a system D
|
|
' SN in this example
|
|
Set Con = Server.CreateObject("ADODB.Connection")
|
|
|
|
'Name of your DSN
|
|
Con = "YourDSN"
|
|
'Sets the RecordSet
|
|
Set RS = Server.CreateObject("ADODB.Recordset")
|
|
'Your SQL string, this will generate the
|
|
' Average Number "AS" Average all on the S
|
|
' erver
|
|
SQLString = "SELECT AVG(tblOfRecord.the_colum) AS Average FROM tblOfRecord WHERE "
|
|
SQLString = SQLString & "tblOfRecord.Your_ID='" & strYourID & "' "
|
|
|
|
'Open it all up
|
|
RS.Open SQLString,Con
|
|
'Get the Averaged number
|
|
strNum = RS("Average")
|
|
'Fix the number so you dont have a bunch
|
|
' of 2.3333333,this will display i.e 2.3
|
|
strNumFixed = FormatNumber(strNum,1)
|
|
'Display the Correct HTML for your numbe
|
|
' r, make it to how you wish.
|
|
Response.Write "<HTML>"
|
|
Response.Write "<HEAD>"
|
|
Response.Write "<TITLE>" & "AverageNumber" & "</TITLE>"
|
|
Response.Write "<META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">" 'Dont have To have this
|
|
Response.Write "</HEAD>"
|
|
Response.Write "<BODY bgcolor=""#FFFFFF"" text=""#000000"">"
|
|
Response.Write "<B>" & strNumFixed & "</B>"
|
|
Response.Write "</BODY>"
|
|
Response.Write "</HTML>"
|
|
' If you are looping through displaying
|
|
' more then one average then use the follo
|
|
' wing format
|
|
' add the same code as above except drop
|
|
' the
|
|
' strNum = RS("Average") and strNumFixed
|
|
' and formatnumber code
|
|
' Uncomment this code out
|
|
' WHILE NOT RS.EOF
|
|
' IF NOT IsNull(RS("Average") ) THEN
|
|
' Response.Write "<b>" & FormatNum
|
|
' ber(RS("Average"),1) & "</b>"
|
|
' ELSE
|
|
' Response.Write "no average"
|
|
' END IF
|
|
' RS.MoveNext
|
|
' WEND
|
|
'And thats about it works pretty simple
|
|
' and alot less code
|
|
%> |