Solved

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

Posted on 2010-11-18
16
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34170152
can you post the query you are using.
0
 

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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34170185
that is not the query i posted.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

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