I'm hoping someone can help. Here's my problem.

Lets say I'm building a report where I query SQL for data and display the individual lines and show a sum at the bottom...

Example:

Code:
<%
    do until rsData.EOF
%>
        <tr>
            <td><%=rs("NAME")%></td>
            <td><%=rs("SALES")%></td>
        </tr>

<%
    TTL_SALE = TTL_SALE + rs("SALES")
    rsData.MoveNext
        loop
    rsData.Close
%>

        <tr>
            <td>TOTAL</td>
            <td><%=TTL_SALE%></td>
        </tr>
The output would be like:

JOHN 5
JANE 6
MARK 7
TOTAL 18

Now lets say I want to show the TOTAL at the top, before the detail.

TOTAL 18
JOHN 5
JANE 6
MARK 7


So how does one go about getting the sum appear at the top before the detail, without having the query the SQL server twice ... once for the TOTAL and again for the detail? Is it possible to setup the SQL query as a function, or a way to pull the SQL data into cache to display in different parts of a page?

Thanks!!