473,427 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

Complex Query Criteria (fun challenge, anyone?)

48
Given:
Expand|Select|Wrap|Line Numbers
  1. tblPurchase contains:
  2.      customerID
  3.      dtePickup   'estimated date a customer will return to the shop
  4.  
  5.  
  6. tblPickup contains:
  7.      dteArrived  'the actual date the customer returned
  8.      status      'set to "pickup complete" or "will return another day"
  9.  
I need one query/report which shows all pending pickups, broken down by:
1) Customers who came to the store, but could not pick up their item that day and should be returning soon for that purpose (being, any tblPickup entry where status="will return another day"), and
2) Customers who are anticipated to pickup their item who haven't already, being tblPurchase.dtePickup does not have a corresponding tblPickup.dteArrived within 2 months of it.

I know how to do item #1 alone in a query. I know how to do the reverse of item #2 in a query (that is, find all tblPurchase.dteArrived records that are within DateAdd("m",(+/-)2,tblPickup.dtePickup). However, I have no clue how to ascertain if a corresponding tblPickup record doesn't exist when expected to within that range. So, how do I write query criteria for records that *don't* exist?

If there's some way to combine both #1 and #2 for easy reporting, that would be all the better. Thank you, as always.
Aug 27 '07 #1
5 1509
Rabbit
12,516 Expert Mod 8TB
Given:
Expand|Select|Wrap|Line Numbers
  1. tblPurchase contains:
  2.      customerID
  3.      dtePickup   'estimated date a customer will return to the shop
  4.  
  5.  
  6. tblPickup contains:
  7.      dteArrived  'the actual date the customer returned
  8.      status      'set to "pickup complete" or "will return another day"
  9.  
I need one query/report which shows all pending pickups, broken down by:
1) Customers who came to the store, but could not pick up their item that day and should be returning soon for that purpose (being, any tblPickup entry where status="will return another day"), and
2) Customers who are anticipated to pickup their item who haven't already, being tblPurchase.dtePickup does not have a corresponding tblPickup.dteArrived within 2 months of it.

I know how to do item #1 alone in a query. I know how to do the reverse of item #2 in a query (that is, find all tblPurchase.dteArrived records that are within DateAdd("m",(+/-)2,tblPickup.dtePickup). However, I have no clue how to ascertain if a corresponding tblPickup record doesn't exist when expected to within that range. So, how do I write query criteria for records that *don't* exist?

If there's some way to combine both #1 and #2 for easy reporting, that would be all the better. Thank you, as always.
I'm assuming there's a CustomerID field in tblPickup.

If you outer join the two tables together, any customer who hasn't attempted picked up an item will have null values in tblPickup.

Yes, you can join the two queries together by ORing the criteria.

Here's the problem. What happens when the same customer has more than one order? You should be linking by an OrderID field rather than a CustomerID field.
Aug 27 '07 #2
isoquin
48
Well, it is 100% guaranteed that the customer won't make multiple orders within 5 months of another, which is why I can safely look 2 months in either direction without problem.

I'm unsure of OuterJoin or ORing. Could you possibly point me to a good tutorial?
Sep 5 '07 #3
Rabbit
12,516 Expert Mod 8TB
http://www.w3schools.com/sql/sql_join.asp
When I say outer join, that means left/right joins.

http://www.w3schools.com/sql/sql_and_or.asp
Sep 5 '07 #4
isoquin
48
EDIT: I'll keep the below post for any troubled googler, but I have the answer. I needed itemPickup Is Null, instead of =null

thanks everyone!


[/EDIT]

ok that was good - learned something - almost there.

So I have my left join query (which works great), and wanted to add where statements, along the lines of the following pseudocode

Expand|Select|Wrap|Line Numbers
  1. WHERE itemPickup = "will return"        'so, there's an entry event, but the item still needs to be picked up
  2. OR itemPickup = Null        'the customer didn't come in at all
Now, if I just use the first line (with all appropriate parenthesis and accessories), it works. However, if I use anything like =Null or ="" then nothing comes out on the query. I must be screwing up the syntax, altho I get no angry Access messages.

Ideas?
Sep 5 '07 #5
Rabbit
12,516 Expert Mod 8TB
Good Luck.
Sep 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. ...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
4
by: Tererai | last post by:
Hi guys? I am new to this community, i'm very pleased to join you. For the past 2 weeks i have been trying to specify criteria in a crosstab query but i get a fun message which says"Microsoft Jet...
5
by: RacerX2000 | last post by:
I have an MS access Database (2000) and Have created a form that sets a variable to a value I would like (Based on other selections in the form) to pass to my query criteria and I get the following...
5
by: binky | last post by:
Question for all you SQL gurus out there. I have a (seemingly) complex query to write, and since I'm just learning SQL server, am not sure how to go about it. Tables: t_trans t_account All...
1
by: Coll | last post by:
I'm receiving this message when running a query... This expression is typed incorrectly or is too complex to be evaluated. For example, a numeric expression may contain too many complicated...
4
by: dizzydangler | last post by:
Hi all, I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.