PC Review


Reply
 
 
StuJol
Guest
Posts: n/a
 
      20th May 2010
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.
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      20th May 2010
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.

 
Reply With Quote
 
Daryl S
Guest
Posts: n/a
 
      20th May 2010
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
count duplicats, display incremental count, restart count at changein value JenIT Microsoft Excel Programming 2 24th Aug 2010 09:10 PM
Count unique field1 combined with count field2, both grouped andungrouped john.mctigue@health.wa.gov.au Microsoft Access Queries 3 19th Dec 2008 03:52 AM
Count Employee Work Time - Don't Double-count Overlapping Apts. =?Utf-8?B?Sg==?= Microsoft Excel Worksheet Functions 0 27th Apr 2007 05:52 AM
how to get count(col1), count(col2), count(sol3) with only one query Mario Krsnic Microsoft Access Queries 2 27th Oct 2006 06:52 PM
Count Intervals of Filtered TEXT values in Column and Return Count across a Row Sam via OfficeKB.com Microsoft Excel Worksheet Functions 9 31st Jul 2005 03:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.