Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 October 15th, 2008, 12:25 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Recordset Manipulation


Chaps, Wondering if you can help.

I am currently mapping some SQL results into a graphical output for some trend analysis.

The Results are from a login counter with three fields -

logintable - Example table name

User Unique ID - Field name not needed
Login Count - Example Field name logincount (numeric)
Date Logged - Example Field name datelogged (smalldatetime)


The example results would be

logincount | datelogged
-------------------------
6 15/10/2008
2 15/10/2008
7 15/10/2008
1 14/10/2008
2 14/10/2008
6 13/10/2008
6 13/10/2008

What i am trying to manipulate is to return one instance of the date and the overal count per date eg -

logincount | datelogged
-------------------------
15 15/10/2008
3 14/10/2008
12 13/10/2008

Example Record set retrieval

Code:
rs.Open"Select * from logintable",ConString
Do Until rs.eof
LogCount = rs("logincount")
DateLog = rs("datelogged")
rs.movenext
loop
rs.close
I have played with creating temp arrays and compares but all about as effective as warming your house with a candle.

Any suggestions would be greatly received..

Cheers

Aspless




 
Old October 15th, 2008, 02:04 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Just need to use the right SQL.

<%
...
SQL = "SELECT datelogged, SUM(logincount) AS logins " _
    & " FROM logintable " _
    & " GROUP BY datelogged " _
    & " ORDER BY datelogged"
rs.Open SQL ,ConString
Do Until rs.eof
    Response.Write rs("datelogged") & ": " & rs("logins") & "<br>" & vbNewLine
    rs.movenext
loop
rs.close
%>
 
Old October 15th, 2008, 03:17 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default


Thanks Old Pedant,

I normally find myself using asp to overcome my lack of contructive SQl knowledge.

Noted i need to look much further into SQL's vast functionality.

Cheers

Aspless



 
Old October 15th, 2008, 03:32 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Just to show how you *COULD* do this via ASP (and I am *NOT* recommending this, for such a simple case, but...):
Code:
' avoid using SELECT * and *always* use an ORDER BY
rs.Open "Select datelogged, logincount from logintable ORDER BY datelogged", ConString

priorDate = rs("dateLogged")
sum = 0

Do While True
   dump = rs.EOF
   If Not dump Then dump = priorDate <> rs("datelogged")
   If dump Then
       Response.Write priorDate & "::" & sum & "<br>" & vbNewLine
       sum = 0
   End If
   If rs.EOF Then Exit Do
   priorDate = rs("datelogged")
   sum = sum + rs("logincount")
   rs.MoveNext
Loop
rs.close
...
%>
See why the SQL solution is so much better? <grin/>
 
Old October 15th, 2008, 03:45 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Cheers..

The likelihood would have been my Neanderthal grip of asp would have produced a considerably longer number of lines..

Noted the SQL version is much simpler.. One further light bulb dimly lit.

Cheers

Aspless







Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation YoungLuke C# 4 May 4th, 2007 01:46 AM
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
Treeview Manipulation reyboy VB.NET 2002/2003 Basics 7 March 28th, 2005 09:43 AM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





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