How can i get ASP to take a Certain table in an access database, lets say Cost (cost colum and Systematicly
Add the Values together Giving me the Sum on an seperate
page???
<%
strSql="SELECT sum(cost) as TotalCost FROM myTable"
set conn=server.createobject("ADODB.CONNECTION"
conn.open YourConnectionStringToTheDatabase
set rs=conn.execute(strSql)
If Not rs.eof then
myTotalCost=rs("TotalCost"
ELSE
myTotalCost=0
End IF
set rs=nothing
conn.close
set conn=nothing
response.write("The Total Cost Is: " & myTotalCost)
%>
Am i going to have to Add the values together iN MS Access and have a total Cost Feild? for SQL to pick up from ??
<%
strSql="SELECT sum(cost) as TotalCost FROM myTable"
set conn=server.createobject("ADODB.CONNECTION"
conn.open YourConnectionStringToTheDatabase
set rs=conn.execute(strSql)
If Not rs.eof then
myTotalCost=rs("TotalCost"
ELSE
myTotalCost=0
End IF
set rs=nothing
conn.close
set conn=nothing
response.write("The Total Cost Is: " & myTotalCost)
%>
No, the sql statement is returning the total of all the values in the "cost" field. You won't need to add another column at all, it's doing the math for you then returning the result as a temporary field called TotalCost.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.