Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Professional
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 6th, 2013, 01:52 PM
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..
  #2 (permalink)  
Old June 6th, 2013, 08:01 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Why is running two queries such an issue for you? It may not be possible to alter your query to sum the results. Post your query so we can at least look at it?

here is one option without running another query however that's is what I would do. run a quick select count(*) Where.......

BTW As I have done below, you should ALWAYS wrap an if not rsData.eof around every Do until rsData.eof

Code:
<% if not rsData.eof then
      dim theTotal
      do until rsdata.eof
         theTotal = theTotal + rs("SALES") 
         rsData.MoveNext 
      loop
      rsData.MoveFirst
      ressponse.write "<tr><td>Total</td><td>" & theTotal & "</td></tr>"
      rsData.MoveNext      
      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
   else
      response.write "<i>No data found</i>"
   end if
%>
__________________
Wind is your friend
Matt


Similar Threads
Thread Thread Starter Forum Replies Last Post
data output kciwzehc Access 5 November 28th, 2007 01:10 PM
Output loop data to a string iloveoatmeal Classic ASP Basics 2 December 22nd, 2005 08:28 PM
About output data to excel momowu0701 Beginning VB 6 0 March 1st, 2005 09:31 AM
query about data dispay in dbgrid. cbpanchal VB Databases Basics 1 July 8th, 2003 04:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.