Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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
 
Old November 4th, 2004, 06:40 AM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default how can i display the totals only

I have some code I have written to list the total number of PC's in each department of each location of our business. So you should see the following output.

Location 1
              sales 4
              parts 5
              other 9

Location 2
              accounts 14

However I have got so far but can not get to the totals only, my page comes out as follows

Location 1 sales 1
              sales 2
              sales 3
              sales 4
              parts 1
              parts 2

etc

Can anyone tell me how to display totals only, my code is below

Thanks

Richard





<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Dim rsCitrix
Dim rsCitrix_numRows

Set rsCitrix = Server.CreateObject("ADODB.Recordset")
rsCitrix.ActiveConnection = MM_lee_STRING
rsCitrix.Source = "SELECT * FROM tblCitrix ORDER BY location, department"
rsCitrix.CursorType = 0
rsCitrix.CursorLocation = 2
rsCitrix.LockType = 2
rsCitrix.Open()

rsCitrix_numRows = 0
%>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
  <p><strong>PC's by Location and Department</strong></p>
</div>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>nbsp;</td>
    <td>nbsp;</td>
    <td width="33%"><div align="center">Total PC's</div></td>
  </tr>
      <%
    currentlocation = ""
    currentdept = ""
    nextlocation = rsCitrix("location")
    nextdept = rsCitrix("department")
    mycount = 1
    DO WHILE NOT rsCitrix.EOF = TRUE
        if NOT nextlocation = currentlocation then
            currentlocation = nextlocation
            %>
            <tr>
                <td colspan="3"><%=currentlocation%></td>
            </tr>
                <%
                do while (NOT rsCitrix.EOF = true)
                    if not currentlocation = rsCitrix("location") then
                        currentdept = nextdept
                        nextdept = ""
                        mycount = 1
                        exit do
                    end if

                    currentdept = nextdept
                    rsCitrix.movenext
                    if not rsCitrix.eof = true then
                        nextdept = rsCitrix("department")
                    else
                        exit do
                    end if
                    if currentdept = nextdept then
                        mycount = mycount + 1
                    else
                        mycount=1
                    end if

                    %>
                    <tr>
                        <td width=33%>&nbsp;</TD>
                        <td width=33%><%=rsCitrix("department")%></td>
                        <td width=33%><%=mycount%></td>
                    </tr>
                    <%

                LOOP
        end if
        if not rsCitrix.eof = true then
            'rsCitrix.movenext()
            nextlocation = rsCitrix("location")
        end if
    LOOP
    %>
</table>

</body>
</html>
<%
rsCitrix.Close()
Set rsCitrix = Nothing
%>


 
Old November 4th, 2004, 07:57 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

Can you have a different query result with Sum(xxx) group by etc., and try to display result at the end of the details.


Gokulan Ethiraj
 
Old November 4th, 2004, 06:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Richard,

I can understand that you are trying to list the details for every location. But can you name the header for the data displayed within each location? What is the column used in the table?

Location 1
Hope this is department what is this, is that the count of department for that location?
              sales 4
              parts 5
              other 9

Gokul,

Using another query that has sum(xxx) wouldn't help, as Richard is looking for the sub total, which has to be displayed at the end of every location(If I am right). Also the method that you suggested would hit the DB for every location, thus would have make as many connections as number of locations to the DB.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old November 5th, 2004, 05:59 AM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

each record in the database is for 1 computer so I am trying to list number of PC's per department, per franchise

location department number of PC's
location1 sales 5
                      service 4

location2 sales 8
                      admin 2

Thanks Vijay

 
Old November 9th, 2004, 07:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Hope this is what you are looking for.
Code:
select location, department, count(*) as NumOfPCs 
from tblCitrix 
group by location, department 
order by location, department
This would create list of locations, its relavant department and count of records per department, which you can loop through in your ASP page and display the location only when it changes, so that you get the Location_NAME displayed per location and display the other columns as such.

Feel free to post here for any clarifications.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Report totals rwahdan BOOK: Access 2003 VBA Programmer's Reference 2 February 5th, 2008 03:56 AM
Totals not working rsm42 ASP.NET 1.0 and 1.1 Basics 1 December 20th, 2006 06:55 AM
Help with totals rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 15th, 2006 01:18 PM
Totals not accurate! dba123 Reporting Services 1 February 5th, 2006 10:53 PM
Totals bjackman Access 1 February 8th, 2004 09:27 PM





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