View Single Post
 
Old June 6th, 2013, 01:52 PM
crabjoe crabjoe is offline
Authorized User
Points: 254, Level: 5
Points: 254, Level: 5 Points: 254, Level: 5 Points: 254, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: , , .
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to dispay parts of queried data in different sections of output?

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!!

Last edited by crabjoe; June 6th, 2013 at 01:56 PM..