473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

counting DB entry values (not rows)

How do I add up the values of the data from all of the rows returned? i.e -
I have a DB, with 148 rows of client info, and I want to addup all the
scores. Each entry's score differes. Here is the code I have sofar:

SQL = "select * from company_scores order by company_name"
Set objRS = Server.CreateOb ject("ADODB.Rec ordset")

objRS.CursorLoc ation = adUseServer
objRS.CursorTyp e = adOpenStatic
objRS.ActiveCon nection = objConn
objRS.open SQL, objConn

i=0
icount = 0
Do until objRS.EOF
company_name = objRS("company_ name")
'currentday = day(objRS("sDat e"))
'currentmonth = month(objRS("sD ate"))
'currentyear = year(objRS("sDa te"))

'Select Case currentmonth
'Case 1 iMonth = "January"
'Case 2 iMonth = "February"
'Case 3 iMonth = "March"
'Case 4 iMonth = "April"
'Case 5 iMonth = "May"
'Case 6 iMonth = "June"
'Case 7 iMonth = "July"
'Case 8 iMonth = "August"
'Case 9 iMonth = "September"
'Case 10 iMonth = "October"
'Case 11 iMonth = "November"
'Case 12 iMonth = "December"
'End Select

'thecurrentdate = Cstr(currentday ) & " " & iMonth & " " &
Cstr(currentyea r)
on error resume next

iCompliments = objRS("complime nts")
iComplaints = objRS("complain ts")
If iCompliments < 1 Then iCompliments = 0
If iComplaints < 1 Then iComplaints = 0
If isnull(iComplim ents) Then iCompliments = 0
If isnull(iComplai nts) Then iComplaints = 0
tCompliments = iCompliments + iCompliments
tComplaints = iComplaints + iComplaints

If isnull(objRS("s core")) then
myendscore = "No data yet"
Else
myendscore = objRS("score") & "/" & 10
End If

if i=0 then
tdcolor="#CEC6D 6"
i=1
Else
tdcolor="#BCB1C 7"
i=0
End if
%>
<TR>
<TD COLSPAN="5"><IM G SRC="images/blank.gif" WIDTH=2
HEIGHT=2></TD>
</TR>
<TR>
<TD WIDTH="862" VALIGN="top" BGCOLOR="<%=tdc olor%>">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" >
<TR>
<TD WIDTH="7"><IMG SRC="images/blank.gif" WIDTH="7"
HEIGHT="3"></TD>
<TD VALIGN="top" ALIGN="left" CLASS="cwc">
<%company_name= trim(company_na me)

%> <B><SPAN CLASS="link1">< A HREF =
"cwcsearch.asp? searchby=1000&l ocation=&city=& Country=0&suppl ier=<%=company_ n
ame%>&keyword=& industry=non&al ias=&cwc=Y" TITLE="Click here to see recent
comments">
<%=company_name %></A></SPAN></B> </TD>
</TR>
</TABLE></TD>
<TD WIDTH="45" ALIGN="RIGHT" VALIGN="middle"
BGCOLOR="<%=tdc olor%>" CLASS="cwc"><%= iCompliments%></TD>
<TD WIDTH="45" ALIGN="RIGHT" VALIGN="middle"
BGCOLOR="<%=tdc olor%>" CLASS="cwc"><%= iComplaints%></TD>
<TD WIDTH="7" BGCOLOR="<%=tdc olor%>" CLASS="cwc"><IM G
SRC="images/blank.gif" WIDTH="7" HEIGHT="3"></TD>
<%
icount = icount +1
ObjRS.Movenext
Loop

I now want to display the total amount of Compliments and the total amount
of Complaints.As you can see, i tried the following approach, but it didn't
work out:

iCompliments = objRS("complime nts")
iComplaints = objRS("complain ts")
If iCompliments < 1 Then iCompliments = 0
If iComplaints < 1 Then iComplaints = 0
If isnull(iComplim ents) Then iCompliments = 0
If isnull(iComplai nts) Then iComplaints = 0
tCompliments = iCompliments + iCompliments
tComplaints = iComplaints + iComplaints

Thanx :)

--

Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
Jul 19 '05 #1
1 1253

"Lord Merlin" <SP4M_Rudi@SP4M _Bonzai.org.za_ SP4M> wrote in message
news:Tb******** ************@is .co.za...
How do I add up the values of the data from all of the rows returned? i.e - I have a DB, with 148 rows of client info, and I want to addup all the
scores. Each entry's score differes. Here is the code I have sofar:


I think you could do this with all one a single record resultset, like:

SQL = "SELECT SUM(compliments ),SUM(complaint s) FROM company_scores"
objConn.Open <your connection string>
Set objRS = objConn.Execute (SQL)
iCompliments = objRS.Fields.It em(0).Value
iComplaints = objRS.Fields.It em(1).Value
objRS.Close : Set objRS = Nothing
objConn.Close : Set objConn = Nothing

Ray at work
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1443
by: DavidC | last post by:
Anyone know how to count rows in a table depending on 2 columns, and different values within the second column. Basically i am trying to obtain the resultset example below from the table example below TABLE example: Date | Status -------------------------
16
1735
by: walexand | last post by:
I use the database mysql v.4. My problem is... I have a select like: select * from user where language = "de"; the result are then: id name =================== 1 max
8
1790
by: mgm | last post by:
hello, I have a query that is supposed to return only 1 record, however I recently found that because of an error in the database it can return more than 1. So what I need to do is capture if it is more than 1 record and alert the user to contact the database administrator. How can I get the count of records returned by a recordset? Is there no way besides looping through with a counter variable?
2
1762
by: Adam | last post by:
In my MYISAM table I have an index (Index_A) on 2 fields (Field_A, Field_B). There are millions of rows in the table. The cardinality of Index_A is 53. I think a query to count the number of rows that match a pair of values for Field_A and Field_B should execute blindingly fast (in the index count the number of leaf nodes for the B-Tree node representing the indexed pair of values). My query looks like: SELECT count(*) FROM `table_A`...
1
2392
by: nek | last post by:
Greetings, We try to automate database creation via script which gets executed remotely for a number of servers. This works fine for most of the servers. However, it occasionally fails some of them for certain reasons (eg. authorization, communication down) and results in dummy entry in 'System Database Directory' as follows:
3
2065
by: Peter | last post by:
Hi, This post is about counting rows and finding the max count in a group of rows. I'm trying to find the player who scored the most goals in a game. I know how to find out how many goals the players scored, but I do not know how to find the player who scored the most goals in a specific game. The tables:
4
1894
by: BJ | last post by:
Can anyone tell me how to include a count of group records in a group footer. I know (I think I know!) that I have to include an unbound text box in the footer, but what expressions do I use to count the entries within a group (subtotals I suppose). eg: the column (group) headings are something like this: Area Surname London Smith Giles
2
1497
by: Bill Nguyen | last post by:
I ran into Excel alphanumeric data column import using ADO.NEt. Upon searching, I found this solution, but it requires edit a registry entry as follow: Hkey_Local_Machine/Software/Microsoft/Jet/4.0/Engines/Excel/TypeGuessRowsThat says how many rows to scan to guess the datatype. The default is 8, but you can set it anywhere from 0-16 decimal (0 meaning "scan the first 16384 rows", and all other values meaning what they say). Putting this...
2
2845
by: vspsdca | last post by:
Hi, I'm quite new to the world of VBA so any help you could extend will help me a lot with my project. I have a database of Change Requests from our users. I have two date boxes, one is Date Request Raised and Deadline for Entry. What I'd like to happen is when I enter the date on the Date Request Raised the Deadline for Entry would automatically be filled based on the Asset type that was selected. For example: if the asset type = 2...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.