Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Colum Addition

Status
Not open for further replies.

LinuxGuy

Programmer
Nov 18, 2002
37
0
0
US
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???
 
The SQL will do it:
SELECT sum(cost) as TotalCost FROM myTable
 
But How do i Implement that into my Code?

SELECT sum(cost) as TotalCost FROM myTable

i want the total Costs to be displayed on the First PAge .
can i email u my Code?
 
<%
strSql=&quot;SELECT sum(cost) as TotalCost FROM myTable&quot;
set conn=server.createobject(&quot;ADODB.CONNECTION&quot;)
conn.open YourConnectionStringToTheDatabase
set rs=conn.execute(strSql)
If Not rs.eof then
myTotalCost=rs(&quot;TotalCost&quot;)
ELSE
myTotalCost=0
End IF
set rs=nothing
conn.close
set conn=nothing

response.write(&quot;The Total Cost Is: &quot; & 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=&quot;SELECT sum(cost) as TotalCost FROM myTable&quot;
set conn=server.createobject(&quot;ADODB.CONNECTION&quot;)
conn.open YourConnectionStringToTheDatabase
set rs=conn.execute(strSql)
If Not rs.eof then
myTotalCost=rs(&quot;TotalCost&quot;)
ELSE
myTotalCost=0
End IF
set rs=nothing
conn.close
set conn=nothing

response.write(&quot;The Total Cost Is: &quot; & myTotalCost)
%>
 
No, the sql statement is returning the total of all the values in the &quot;cost&quot; 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.

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Not based on this example. This SQL does the totaling. You could on the other hand create a query in Access using this SQL statement and use:

strSql=&quot;SELECT TotalCost FROM yourTotalsQuery&quot;

Both ways will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top