I have a table that displays the rsults of a sql query. It would be nice to add the totals at the bottom of the table. anyone have ideas on how to do this?
Printable View
I have a table that displays the rsults of a sql query. It would be nice to add the totals at the bottom of the table. anyone have ideas on how to do this?
I don't know what scripting language you're using, but assuming you're using VBScript, just create a varialbe for each item plus another variable for the total, and calculate as such:
Dim item1, item2, item3, total
total = item1 + item2 + item3
And if you have a recordset object, you can just assign the value of the query to the items as such:
item1 = rs("Item1")
item2 = rs("Item2")
... etc
Hope this helped.
Just use a variable to add up the total as as you move through the recordset.
Can you display your example with code for the table...
I'm not sure what you need to do specifically but here is a simple example:
rsRecordSet.Open "SELECT Name, Total FROM Table"
Dim iTotal as integer
iTotal = 0
Do while NOT rsRecordSet.EOF
Response.Write rsRecordSet("Name")
Response.Write rsRecordSet("Total")
iTotal = iTotal + rsRecordSet("Total")
rsRecordSet.MoveNext
Loop
Response.WRite "Total"
Response.Write iTotal
yeah, how about you show us some source, at least your query, or else we don't know what you're working with...
Let your SQL server do the calculation.. add sum() columns at the end of your query and use them in your last row of your table.