Solved

MS Access Query to find items that are S but not P

Posted on 2010-11-18
16
303 Views
Last Modified: 2012-08-14
I have an Item Master Location File (F41021).
Items in the table can have a Primary Location indicated by LPBIN = ‘P’ and
The items can have a Secondary Location indicated by LPBIN  = ‘S’.

There are some Items (LIITM) that have a Secondary Location (LPBIN  = ‘S’) but have no Primary Location (LPBIN = ‘P’).

I am having a ‘Brain Cloud’ and cannot remember how I created this MS Access Query once before.

Basically, I am trying to Query the F41021 table and create a list of item numbers (LIITM) that have a Secondary Location (S) but have no Primary Location (P).

Can you help me jog my memory?

SELECT PRODDTA_F41021.LIITM, PRODDTA_F41021.LIMCU, PRODDTA_F41021.LIPBIN
FROM PRODDTA_F41021
GROUP BY PRODDTA_F41021.LIITM, PRODDTA_F41021.LIMCU, PRODDTA_F41021.LIPBIN
HAVING (((PRODDTA_F41021.LIMCU)="       31101"));

Tw
0
Comment
Question by:Tom Winslow
  • 8
  • 7
16 Comments
 
LVL 5

Expert Comment

by:bboswell
ID: 34168306
Can you possibly give us an extract or example of the table to be checked... say 5-10 rows this will help to understand better.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34168379

try this query


select *
from PRODDTA_F41021
where LPBIN  = 'S' and LIITM not in (select LIITM from PRODDTA_F41021 as P where  LPBIN  = 'P')
0
 

Author Comment

by:Tom Winslow
ID: 34170048
Uploading top 5 records.
F41021Sample.xls
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170054
TomWinslow,

did you try the query i posted?
0
 

Author Comment

by:Tom Winslow
ID: 34170074
Yes. Could not make it work.

It runs but finds no data.

select *
from PRODDTA_F41021
where LiPBIN  = 'S' and LIITM not in (select LIITM from PRODDTA_F41021 as P where  LiPBIN  = 'P')

tw
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170087
the sample file you uploaded will not return any record because there is no record with LiPBIN  = 'S'
0
 

Author Comment

by:Tom Winslow
ID: 34170144
Hmmm...

I messed up with only 5 records. This file contains 1370 records and some examples.

tw

F41021Sample2.xls
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170152
can you post the query you are using.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:Tom Winslow
ID: 34170183
SELECT PRODDTA_F41021.LIITM, PRODDTA_F41021.LIMCU, PRODDTA_F41021.LIPBIN
FROM PRODDTA_F41021
WHERE (((PRODDTA_F41021.LIMCU)="       31101") AND ((PRODDTA_F41021.LIPBIN)="P" And Not (PRODDTA_F41021.LIPBIN)="S"));
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170185
that is not the query i posted.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170194
copy and paste this query


SELECT *
FROM PRODDTA_F41021
WHERE LIPBIN  = 'S' and LIITM not in (select LIITM from PRODDTA_F41021 as P where  LIPBIN  = 'P');
0
 

Author Comment

by:Tom Winslow
ID: 34170195
Oh. This is the one you posted.

SELECT *
FROM PRODDTA_F41021
WHERE (((PRODDTA_F41021.LIPBIN)='S') AND ((PRODDTA_F41021.LIITM) Not In (select LIITM from PRODDTA_F41021 as P where  LiPBIN  = 'P')));

I added one more filter:

SELECT *
FROM PRODDTA_F41021
WHERE (((PRODDTA_F41021.LIPBIN)='S') AND ((PRODDTA_F41021.LIITM) Not In (select LIITM from PRODDTA_F41021 as P where  LiPBIN  = 'P')))
GROUP BY PRODDTA_F41021.LIMCU
HAVING (((PRODDTA_F41021.LIMCU) Like "*31101"));

tw

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34170205
this query return 3 records


SELECT *
FROM PRODDTA_F41021
WHERE LIPBIN  = 'S' and LIMCU Like '*31101' and LIITM not in (select LIITM from PRODDTA_F41021 as P where  LIPBIN  = 'P');
0
 

Author Comment

by:Tom Winslow
ID: 34170238
I pasted the SQL into the Access  query but it still returns no records. I do not understand. The Query looks good.

tw

ScreenShot.bmp
ScreenShot1.bmp
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34170334


see this sample db, run query1
db1.mdb
0
 

Author Closing Comment

by:Tom Winslow
ID: 34174889
Thanks.

tw
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now