Solved

How do I count records from a Statement, however if the same record is multiple, then count them together

Posted on 2015-02-06
14
74 Views
Last Modified: 2015-02-08
want to show a count of some records

however some records values will be the same, so I want these counted as multiple.

eg
SYD 1
MEL 2
DPS 4

not
SYD
MEL
DPS
MEL
DPS
DPS
DPS

is there a way of showing this?
0
Comment
Question by:Graeme
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 300 total points
ID: 40595082
using a query

select [FieldName], Count([FieldName])
from tableName
group by  [FieldName]
0
 

Author Comment

by:Graeme
ID: 40595090
Thanks for that I have correct my query so that it works

Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")                                          

How do I show the count of each record?

eg
SYD 1
MEL 2
DPS 4
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595092
You can also try:
select distinct  [FieldName], Count([FieldName]) from tableName
group by  [FieldName]
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595095
Or
select count(distinct FieldName), FieldName
from tableName
group by  FieldName
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40595097
Since this is just a simple function in access, I might suggest using the query wizard to find Duplicates.
Then you may modify the query by removing the >1 criteria, either in design view or sql view.

This helps in improving your access programming. You may modify the query to get other functions, like Sum or Count, by replqacing Count or adding to it.
0
 

Author Comment

by:Graeme
ID: 40595159
Hey all, just need the code to show the records and how many of each
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40595214
where do you want to show the records?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Graeme
ID: 40595216
As a list

eg
SYD 1
MEL 2
DPS 4

is this what you meant?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40595225
As a list , where ?
0
 

Author Comment

by:Graeme
ID: 40595244
Sorry I do not get what you mean by 'where' ?

Here is the code:

<%
Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")							
%>
	<tr>
		<td colspan=8 align=center>Destinations</td>
		<td colspan=2>&nbsp;</td>
	</tr>
	<tr>
		<td height=20 width=20% colspan=2>0%</td>
		<td height=20 width=20% colspan=2>25%</td>
		<td height=20 width=20% colspan=2>50%</td>
		<td height=20 width=20% colspan=2>75%</td>
		<td height=20 width=20% colspan=2>100%</td>
	</tr>
<%
	Do While Not KPIsDest.eof
%>
	<tr>
		<td colspan=8>
			<table width=100% border=0>
				<tr>
					<td height=20 bgcolor=black width=<%=FormatNumber(((!!!!!!!/EnqCount)*100),2)%>%></td>
					<td height=20>&nbsp;</td>
				 </tr>
			</table>
		</td>
		<td><%=KPIsDest("enq_dest")%></td>
		<td><%=FormatNumber(((!!!!!!!!!/EnqCount)*100),2)%>% Destinations Strikerate</td>
	</tr>
<%
	KPIsDest.MoveNext 
		LOOP
	KPIsDest.Close
%>

Open in new window


where i have the !!!!! is where i need the sum count total of the destinations
0
 
LVL 84
ID: 40595489
So you want to show this on a web page. That's what Rey was asking. We don't know what programming environment you're using, so asking us "how to  show a list" doesn't make much sense to us.

You'd have to loop through the recordset and add rows to your table:

Do Until kpIsDest.EOF
<tr>
            <td colspan=8>
                  <table width=100% border=0>
                        <tr>
                              <td height=20 bgcolor=black width=<%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>%></td>
                              <td height=20>&nbsp;</td>
                         </tr>
                  </table>
            </td>
            <td><%=KPIsDest("enq_dest")%></td>
            <td><%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>% Destinations Strikerate</td>
      </tr>
Loop
0
 

Author Comment

by:Graeme
ID: 40596718
hello and thanks for clarifying...

KPIsDest("YourNumberColumn") being what ?

what do you need from me to figure out which column i am looking for?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 200 total points
ID: 40596749
YourNumbercolumn is the column from your SQL statement which would contain the value you want to show. It would be either "eng_dest", or the COUNT(eng_dest) column. Since I assume it's the COUNT column, you might change the SELECT statement to this:

SELECT enq_dest, COUNT(enq_dest) AS DestCount FROM enq WHERE enq_date etc etc

Then refer to it like this:

kpIsDest("DestCount")
0
 

Author Closing Comment

by:Graeme
ID: 40597492
Cheers all for your help!

works a treat!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now