A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

count qry



 
 
Thread Tools Display Modes
  #1  
Old May 20th, 2010, 12:25 PM posted to microsoft.public.access.queries
StuJol
external usenet poster
 
Posts: 122
Default count qry

using access 2003 i have the following qry

SELECT DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*]))
AS [Date], [AlarmData Table Filtered by Date].[Event Type], [AlarmData Table
Filtered by Date].Parameter, [AlarmData Table Filtered by Date].Desc2,
Count(*) AS MyCount, [AlarmData Table Filtered by Date].Module
FROM [AlarmData Table Filtered by Date]
GROUP BY
DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*])),
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered by
Date].Parameter, [AlarmData Table Filtered by Date].Desc2, [AlarmData Table
Filtered by Date].Module
HAVING ((([AlarmData Table Filtered by Date].[Event Type])="CHANGE") AND
(([AlarmData Table Filtered by Date].Parameter) Like "*OPSUP") AND
(([AlarmData Table Filtered by Date].Desc2)="NEW VALUE = 1"));

im trying to count number of entries per date but keeps returning 1 and
several instances of same date.
Ads
  #2  
Old May 20th, 2010, 02:01 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default count qry

I've assigned an alias to the table to make this query easier to type. Also
moved the filtering conditions into a Where clause for efficiency and used the
DateValue function to strip off the time instead of using the DateSerial
function with three other functions calls.

SELECT DateValue([Date/Time*]) AS [Date]
, [A].[Event Type]
, [A].Parameter
, [A].Desc2
, Count(*) AS MyCount
, [A].Module
FROM [AlarmData Table Filtered by Date] AS A
WHERE[A].[Event Type]="CHANGE" AND
[A].Parameter Like "*OPSUP" AND
[A].Desc2="NEW VALUE = 1"
GROUP BY DateValue([Date/Time*]),
[A].[Event Type], [A].Parameter, [A].Desc2, [A].Module

If you want a count by date you need to change the query to eliminate the
other fields that you don't want to group by. Perhaps the following -
although you may want to eliminate Module also.

SELECT DateValue([Date/Time*]) AS [Date]
, Count(*) AS MyCount
, [A].Module
FROM [AlarmData Table Filtered by Date] AS A
WHERE[A].[Event Type]="CHANGE" AND
[A].Parameter Like "*OPSUP" AND
[A].Desc2="NEW VALUE = 1"
GROUP BY DateValue([Date/Time*])
, [A].Module

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

StuJol wrote:
using access 2003 i have the following qry

SELECT DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*]))
AS [Date], [AlarmData Table Filtered by Date].[Event Type], [AlarmData Table
Filtered by Date].Parameter, [AlarmData Table Filtered by Date].Desc2,
Count(*) AS MyCount, [AlarmData Table Filtered by Date].Module
FROM [AlarmData Table Filtered by Date]
GROUP BY
DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*])),
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered by
Date].Parameter, [AlarmData Table Filtered by Date].Desc2, [AlarmData Table
Filtered by Date].Module
HAVING ((([AlarmData Table Filtered by Date].[Event Type])="CHANGE") AND
(([AlarmData Table Filtered by Date].Parameter) Like "*OPSUP") AND
(([AlarmData Table Filtered by Date].Desc2)="NEW VALUE = 1"));

im trying to count number of entries per date but keeps returning 1 and
several instances of same date.

  #3  
Old May 20th, 2010, 02:54 PM posted to microsoft.public.access.queries
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default count qry

StuJol -

If you only want the results by date, then remove any fields from the query
that are not limited to one choice (in the WHERE or HAVING clauses), or are
the ones you want to count by (e.g. the date). Any other fields in the GROUP
BY will cause multiple records for each date. In this case, the "[AlarmData
Table Filtered by Date].Module" could contain multiple values, and the
[AlarmData Table Filtered by Date].Parameter could have multiple values. The
criteria is OK, but you don't want to group by or dislplay this last field.

I think you also might want to look into DateValue function instead of the
DateSerial expression you used. You can check out what I used - much simpler.

This is untested, but you get the idea:

SELECT DateValue([Date/Time*])AS [Date],
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered
by Date].Desc2,
Count(*) AS MyCount
FROM [AlarmData Table Filtered by Date]
GROUP BY DateValue([Date/Time*]),
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered
by Date].Desc2
WHERE ((([AlarmData Table Filtered by Date].[Event Type])="CHANGE") AND
(([AlarmData Table Filtered by Date].Parameter) Like "*OPSUP") AND
(([AlarmData Table Filtered by Date].Desc2)="NEW VALUE = 1"));

If you have issues, post your new SQL and give us an example of the output...

--
Daryl S


"StuJol" wrote:

using access 2003 i have the following qry

SELECT DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*]))
AS [Date], [AlarmData Table Filtered by Date].[Event Type], [AlarmData Table
Filtered by Date].Parameter, [AlarmData Table Filtered by Date].Desc2,
Count(*) AS MyCount, [AlarmData Table Filtered by Date].Module
FROM [AlarmData Table Filtered by Date]
GROUP BY
DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*])),
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered by
Date].Parameter, [AlarmData Table Filtered by Date].Desc2, [AlarmData Table
Filtered by Date].Module
HAVING ((([AlarmData Table Filtered by Date].[Event Type])="CHANGE") AND
(([AlarmData Table Filtered by Date].Parameter) Like "*OPSUP") AND
(([AlarmData Table Filtered by Date].Desc2)="NEW VALUE = 1"));

im trying to count number of entries per date but keeps returning 1 and
several instances of same date.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2004-2018 OfficeFrustration.
The comments are property of their posters.