Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 19th, 2003, 10:47 AM
ironchef ironchef is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Cleveland
Posts: 112 ironchef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 34 sec
Reputation Power: 6
problem with sql code...can you see it?

I'm trying to run a query that figures total volunteer turnover between certain dates entered by a user. This is my code and and below that is the error it returns. By the way, I'm working with Access 2000.

Code:
SELECT Count(Volunteers.StatusNo) AS [Active - Inactive Volunteer Turnover]
FROM Volunteers 
GROUP BY Volunteers.StatusNo
HAVING (((First(Volunteers.StatusNo))=4) AND ((Count(Volunteers.StatusNo))>1) 
AND ((Volunteers.IDate)>=[forms]![Report Date Range]![BeginDate] 
And (Volunteers.IDate)<=[forms]![Report Date Range]![EndDate]));


Error:
You tried to execute a query that does not include the specified expression 'First(Volunteers.StatusNo)=4
And Count(Volunteers.StatusNo)>1 And Volunteers.IDate>=[forms]![Report Date Range]![Begin Date]
And Volunteers.IDate<=[forms]![Report Date Range]![End Date])' as part of an aggregate function.

However the query runs fine when I take out the
"
AND ((Volunteers.IDate)>=[forms]
![Report Date Range]![BeginDate]
And (Volunteers.IDate)<=[forms]![Report Date Range]![EndDate]));
"

Thanks in advanced.

Brad

Reply With Quote
  #2  
Old December 19th, 2003, 11:16 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 34 m 33 sec
Reputation Power: 981
take the conditions that apply to individual rows out of the HAVING and put them into the WHERE clause

HAVING is only for conditions which apply to the group

also, if you're gonna group on something (StatusNo), then you pretty much have to include it in the SELECT list -- not because of syntax, you don't have to do it because of syntax, but because without it you will simply get a list of counts and you won't know which StatusNo they belong to

rudy

Reply With Quote
  #3  
Old December 19th, 2003, 12:27 PM
ironchef ironchef is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Cleveland
Posts: 112 ironchef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 34 sec
Reputation Power: 6
maybe you can help?

I guess if I explain exactly what I'm trying to do you might be able to understand if I'm doing it the best way.

Volunteers have different statuses (i.e. Prospect, Applicant, Active, Inactive, Leave of Absence) with dates related to them. StatusNo relates to the statuses (1, 2, 3, 4, 5) respectively. For instance, I might become active on 12/12/2003 and inactive on 12/30/2003. I'm trying to build a query that displays volunteer turnover from active to inactive in relation with between dates that a user inputs. But all I need is the total turnover number. So, the number of Active to Inactive between 12/12/2003 - 12/30/2003 is 20.

StatusNo Status
1 Prospect
2 Applicant
3 Active
4 Inactive
5 LOA

I am working out of the Volunteers table only. I have attached a diagram for reference.

Thanks for your insight.
Attached Images
File Type: jpg diagram.jpg (82.0 KB, 62 views)

Last edited by ironchef : December 19th, 2003 at 12:34 PM.

Reply With Quote
  #4  
Old December 19th, 2003, 03:26 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 34 m 33 sec
Reputation Power: 981
if you use conditions in the WHERE clause to select only those rows you want, and if they all have the same status, then you don't need to GROUP BY

in effect, you allow the entire result set to become a single group, and you can still use aggregate fucntions like COUNT()
Code:
select Count(Volunteers.StatusNo) 
                 as [Active - Inactive Volunteer Turnover]
  from Volunteers 
 where Volunteers.StatusNo = 4
   and Volunteers.IDate 
       between [forms]![Report Date Range]![BeginDate] 
           and [forms]![Report Date Range]![EndDate]
rudy

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > problem with sql code...can you see it?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway