MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

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 7th, 2004, 09:25 AM
bbobble bbobble is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Ohio
Posts: 37 bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 20 m 9 sec
Reputation Power: 11
A "for all" query in MS Access?

I have three tables, Equipment, LookUpGroups, and EquipmentGroups.

Equipment
----------
TagNumber
LocationCode

LookUpGroups
-------------
GroupTagNumber
TagNumber

EquipmentGroups
----------------
GroupTagNumber

I want my query to return the GroupTagNumber ONLY IF all of the TagNumbers in that group have a given LocationCode (Given by User).

Example:
GroupTagNumber: G1
TagNumber: A1
LocationCode: 1

GroupTagNumber: G1
TagNumber: A2
LocationCode: 2

GroupTagNumber: G2
TagNumber: A3
LocationCode: 1

So if the user enters LocationCode 1, then he should only get G2 back.

I've started by trying to do a count query:
Code:
SELECT tblEquipmentGroups.GroupTagNumber, tblEquipment.LocationCode
FROM tblEquipmentGroups, tblEquipment, tblLookUpGroups
WHERE tblEquipmentGroups.GroupTagNumber = tblLookUpGroups.GroupTagNumber
  AND tblEquipment.TagNumber = tblLookUpGroups.TagNumber
GROUP BY tblEquipmentGroups.GroupTagNumber, tblEquipment.LocationCode


But really I'm completely stuck. Any help/suggestions would be appreciated!
Thanks,
BB

Reply With Quote
  #2  
Old December 7th, 2004, 09:49 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Code:
SELECT GroupTagNumber
  from tblLookUpGroups lg
 where not exists(select * 
from tblEquipment te
 where te.TagNumber = lg.TagNumber
   and location_code <> <userGivenValue>)

Reply With Quote
  #3  
Old December 7th, 2004, 10:42 AM
bbobble bbobble is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Ohio
Posts: 37 bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level)bbobble User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 20 m 9 sec
Reputation Power: 11
Thanks for responding so quickly!
That almost works. it still returns both G1 & G2 though when the location code entered is 1.

I've played around w/it a ton on my own and this is what I came up with (and *BONUS* it seems to work!):

Code:
SELECT tblEquipmentGroups.GroupTagNumber
FROM tblEquipmentGroups INNER JOIN (tblEquipment INNER JOIN tblLookUpGroups ON tblEquipment.TagNumber=tblLookUpGroups.TagNumber) ON tblEquipmentGroups.GroupTagNumber=tblLookUpGroups.GroupTagNumber
GROUP BY tblEquipmentGroups.GroupTagNumber
HAVING (((Avg(tblEquipment.LocationCode))=[Enter Location Code]));


Wow, this has taken my whole morning!
Thanks again for responding... I appreciate it immensely!
BB

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > A "for all" query in MS Access?


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
Stay green...Green IT