473,394 Members | 1,817 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,394 software developers and data experts.

Can I have your help with a query related problem ?

Hi All

This is probably an easy fix for you experts out there, but the solution is beyond a newbie like me.

I have a table containing several customer fields - with the key field 'Customer' having 3 possible permutations for each customer ie :

'Customer_ID Name Info
10149 ABC Manufacturing Co Enquiry account
10149M ABC Manufacturing Co Machine account
10149S ABC Manufacturing Co Spares Account

The main table can have any combination of these records (ie 1, 2 or all 3 exist in the same table for the same customer)

I need to not return the Customer_ID with the 'S' Suffix.
I want to use the query to return the Customer_ID with the 'M' Suffix UNLESS it doesn't exist, in which case the query should return the Customer_ID without any Suffix.
If both the 'M' & 'No Suffix' records exist, then return the 'M' Suffix

Note: I can't use the 'Name' field to refine the query, as the name is typed by the operator in differing ways (ie ABC Manufacturing Co or ABC Manf Company).

I guess the crux of it is to :

1. Search for the 'M' Suffix' records THEN
2. Search for the 'no Suffix' records IF no 'M' Suffix records exist.

That way I'll get all the 'M' Suffix records listed, together with the 'no Suffix' records (which don't have 'M' Suffix counterparts).

Hope this explains things clearly enough for you.


Thankyou in advance
Mark
Dec 10 '07 #1
5 1088
Rabbit
12,516 Expert Mod 8TB
Seeing as how they are the same people, you would have done better to have a Customer_ID field AND a Suffix field.

This is a three query process. Have one query return all M Suffix records. In this query, also create a column that strips the M off. Have another query that uses an outer join to select the ones without a suffix. Then union them together.
Dec 10 '07 #2
Thankyou for you help !

Sorry, but I'm a little confused with the your answer :-(

1. I have constructed the 1st query (searching for the M suffix in the Customer_ID field & stripping the 'M' off it in another column.

2. I have created a 2nd query which searches the main table & looks for the Customer_ID without the 'M'.

3. the 3rd query (union) doesn't appear to combine query 1 & 2 together (it just seems to return the results of the first part of the SQL statement (ie before the 'UNION ALL' bit.


In essence, I get query 1 to give me a list of customer_ID with 'M's; Query 2 gives me a list of customer_ID without 'M's, but I can't recombine them in a UNION properly.

Is it possible you can give me a little more detail ?

cheers

Mark
Dec 11 '07 #3
Rabbit
12,516 Expert Mod 8TB
Thankyou for you help !

Sorry, but I'm a little confused with the your answer :-(

1. I have constructed the 1st query (searching for the M suffix in the Customer_ID field & stripping the 'M' off it in another column.

2. I have created a 2nd query which searches the main table & looks for the Customer_ID without the 'M'.

3. the 3rd query (union) doesn't appear to combine query 1 & 2 together (it just seems to return the results of the first part of the SQL statement (ie before the 'UNION ALL' bit.


In essence, I get query 1 to give me a list of customer_ID with 'M's; Query 2 gives me a list of customer_ID without 'M's, but I can't recombine them in a UNION properly.

Is it possible you can give me a little more detail ?

cheers

Mark
Did you do the second query with the outer join? What you should do is join on the New ID field in the first query to the ID field in the second query using a right join in this case. Then you keep the ones where the New ID field is Null. And you keep only the ones without an M or an S at the end. This will give you only those records that don't have an M suffix ID.

I think I may have missed a step. When you go to Union two queries, they need to have the same columns. So you might have to drop that New ID field first.
Dec 11 '07 #4
Perfect !

Thankyou for coming back to me; it's all sorted now !

I really appreciate your help - it gets kinda lonely just bashing your head against the Access Manual..

Cheers

Mark
Dec 11 '07 #5
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Dec 11 '07 #6

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

Similar topics

1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
5
by: Darin L. Miller | last post by:
I'm not too good with advanced SQL queries, so please bear with me on this. I have a query with multiple joins that I am trying to get just the last 10 of each unique record (RecordID)...
8
by: Thomas R. Hummel | last post by:
Hello, I am currently working with a data mart. The business wants a view of the data that shows columns from the main table along with up to 6 codes from a related table (not related by the...
9
by: mansoorm | last post by:
I've a db containing two tables which every item in table one is linked to 1--200 items in table 2. I want to generate a report like this: Item in table 1...
2
by: harvindersingh | last post by:
Hello I am trying to compile a query but getting inconsistent data from it. I need to make use of two tables namely: transaction_products refunds Both of the above tables contain...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.