473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to query values from different fields using different criteria?

Hey if anyone is a query pro please showoff some knowledge thx.

Ie: I have a table with :
part
price
location
qty

1 part repeats throughout the table and its price remains the same but
it has multiple locations so I'll have entries like:
cbl201 $0.28 STK1 11
cbl201 $0.28 STK2 13
cbl201 $0.28 STK8 8
cbl201 $0.28 STK11 6
I just want the price and different stock amounts.
But, a regular query will have duplicates and I want the result to
look like
Part: cb1201
Price: $0.28
Stock1:11
Stock2:13
Stock3:8
Stock11:6
I've tried several things to no avail. What may be helpful is that
there is a record of everything in STK1 so I limited my query with
criteria stock_id=STK1
In order to avoid duplicates. But I still want to know the qty stock
for the other ones so I created a new field and in the critera wrote
=[qty_stock] where [stock_id]="STK2" and so on for 3 and 11.. but it's
like I cannot create separate criteria for separate fields or
something. So I tried to put quieries together and I got the
error"SQL statement could not be exe because it contains ambigious
outer joins"
Nov 13 '05 #1
3 2961
For this you will need a report, which can eliminate the duplicates, not
just a query.

Gary
"I_was_here " <ks*****@yahoo. com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
Hey if anyone is a query pro please showoff some knowledge thx.

Ie: I have a table with :
part
price
location
qty

1 part repeats throughout the table and its price remains the same but
it has multiple locations so I'll have entries like:
cbl201 $0.28 STK1 11
cbl201 $0.28 STK2 13
cbl201 $0.28 STK8 8
cbl201 $0.28 STK11 6
I just want the price and different stock amounts.
But, a regular query will have duplicates and I want the result to
look like
Part: cb1201
Price: $0.28
Stock1:11
Stock2:13
Stock3:8
Stock11:6
I've tried several things to no avail. What may be helpful is that
there is a record of everything in STK1 so I limited my query with
criteria stock_id=STK1
In order to avoid duplicates. But I still want to know the qty stock
for the other ones so I created a new field and in the critera wrote
=[qty_stock] where [stock_id]="STK2" and so on for 3 and 11.. but it's
like I cannot create separate criteria for separate fields or
something. So I tried to put quieries together and I got the
error"SQL statement could not be exe because it contains ambigious
outer joins"

Nov 13 '05 #2
Hi,

Well my friend, you have just discovered the reason why *relational*
databases are so much better than *flat-file* databases. <grin>

What you need, IMHO, is 2 *related* tables... (hence the term "relational ")
tblPartsInvento ry -- which store info on the part itself, and
tblLocation -- which stores information on bin locations and quantities.

tblPartsInvento ry
- PartID - PK - AutoNumber ("PK" = Primary Key)
- PartNumber
- Description
- Price(s) ... (i.e. Retail ... Cost ... Core)
.... etc

tblLocation
- LocID - PK - AutoNumber
- PartID - FK - Long Integer ("FK" = Foreign Key)
- Location
- Qty
- CountDate
.... etc

In the relationships window, join the 2 tables (One-to-Many) on PartID

When you get all of that done, I think you'd have to create a cross-tab
query to give you the results that I think you are looking for. (I hate
crosstabs... I think this is right, but I'm not positive.)

TRANSFORM Sum(tblLocation .Qty) AS SumOfQty
SELECT tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber,
tblPartsInvento ry.Description, tblPartsInvento ry.Retail,
tblPartsInvento ry.Cost, tblLocation.Loc ation
FROM tblPartsInvento ry INNER JOIN tblLocation ON tblPartsInvento ry.PartID =
tblLocation.Par tID
GROUP BY tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber,
tblPartsInvento ry.Description, tblPartsInvento ry.Retail,
tblPartsInvento ry.Cost, tblLocation.Loc ation
ORDER BY tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber
PIVOT tblLocation.Cou ntDate;

The results (for sure) could be displayed the way you want them using a
mainform / subform or in a report using grouping.

HTH,
Don
------------------------------------------------------------
I_was_here <ks*****@yahoo. com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
Hey if anyone is a query pro please showoff some knowledge thx.

Ie: I have a table with :
part
price
location
qty

1 part repeats throughout the table and its price remains the same but
it has multiple locations so I'll have entries like:
cbl201 $0.28 STK1 11
cbl201 $0.28 STK2 13
cbl201 $0.28 STK8 8
cbl201 $0.28 STK11 6
I just want the price and different stock amounts.
But, a regular query will have duplicates and I want the result to
look like
Part: cb1201
Price: $0.28
Stock1:11
Stock2:13
Stock3:8
Stock11:6
I've tried several things to no avail. What may be helpful is that
there is a record of everything in STK1 so I limited my query with
criteria stock_id=STK1
In order to avoid duplicates. But I still want to know the qty stock
for the other ones so I created a new field and in the critera wrote
=[qty_stock] where [stock_id]="STK2" and so on for 3 and 11.. but it's
like I cannot create separate criteria for separate fields or
something. So I tried to put quieries together and I got the
error"SQL statement could not be exe because it contains ambigious
outer joins"

Nov 13 '05 #3
Hello Don!!

Thanks for the advice. I forgot to mention in my original post though
that I am trying to avoid creating another table as this is already a
sub table and I have around 5 other tables/queries relying on my
original table so there would be a huge maintenance impact from
changing it. Anyway I see where you were going with the joining of
the tables etc.. but I'm keeping it as one separate table ;) ;). I
decided to create a query that found a unique price and then relating
that to another query. It's not exactly what I wanted but it's
getting me the numbers I need. Merci beaucoup for your time!!!
"Don Leverton" <My*****@Telus. Net> wrote in message news:<86_Cc.165 2$_5.1137@clgrp s13>...
Hi,

Well my friend, you have just discovered the reason why *relational*
databases are so much better than *flat-file* databases. <grin>

What you need, IMHO, is 2 *related* tables... (hence the term "relational ")
tblPartsInvento ry -- which store info on the part itself, and
tblLocation -- which stores information on bin locations and quantities.

tblPartsInvento ry
- PartID - PK - AutoNumber ("PK" = Primary Key)
- PartNumber
- Description
- Price(s) ... (i.e. Retail ... Cost ... Core)
... etc

tblLocation
- LocID - PK - AutoNumber
- PartID - FK - Long Integer ("FK" = Foreign Key)
- Location
- Qty
- CountDate
... etc

In the relationships window, join the 2 tables (One-to-Many) on PartID

When you get all of that done, I think you'd have to create a cross-tab
query to give you the results that I think you are looking for. (I hate
crosstabs... I think this is right, but I'm not positive.)

TRANSFORM Sum(tblLocation .Qty) AS SumOfQty
SELECT tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber,
tblPartsInvento ry.Description, tblPartsInvento ry.Retail,
tblPartsInvento ry.Cost, tblLocation.Loc ation
FROM tblPartsInvento ry INNER JOIN tblLocation ON tblPartsInvento ry.PartID =
tblLocation.Par tID
GROUP BY tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber,
tblPartsInvento ry.Description, tblPartsInvento ry.Retail,
tblPartsInvento ry.Cost, tblLocation.Loc ation
ORDER BY tblPartsInvento ry.Line, tblPartsInvento ry.PartNumber
PIVOT tblLocation.Cou ntDate;

The results (for sure) could be displayed the way you want them using a
mainform / subform or in a report using grouping.

HTH,
Don
------------------------------------------------------------
I_was_here <ks*****@yahoo. com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
Hey if anyone is a query pro please showoff some knowledge thx.

Ie: I have a table with :
part
price
location
qty

1 part repeats throughout the table and its price remains the same but
it has multiple locations so I'll have entries like:
cbl201 $0.28 STK1 11
cbl201 $0.28 STK2 13
cbl201 $0.28 STK8 8
cbl201 $0.28 STK11 6
I just want the price and different stock amounts.
But, a regular query will have duplicates and I want the result to
look like
Part: cb1201
Price: $0.28
Stock1:11
Stock2:13
Stock3:8
Stock11:6
I've tried several things to no avail. What may be helpful is that
there is a record of everything in STK1 so I limited my query with
criteria stock_id=STK1
In order to avoid duplicates. But I still want to know the qty stock
for the other ones so I created a new field and in the critera wrote
=[qty_stock] where [stock_id]="STK2" and so on for 3 and 11.. but it's
like I cannot create separate criteria for separate fields or
something. So I tried to put quieries together and I got the
error"SQL statement could not be exe because it contains ambigious
outer joins"

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2910
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a value for from a combo box. In my query I set the criteria for to ... My query finds the proper values for . Now I also want to find the values...
3
579
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields ...
6
29929
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place....
1
3236
by: Robert | last post by:
I am trying to create a db for service providers by county. I'm relatively new to db programming, but I have done quite a bit of programming ranging from the old basic days up to doing some programming in the HotDocs software. I've kind of accomplished my goal in access, but I'm not quite there yet and figure I've really screwed something...
4
1511
by: Marc DVer | last post by:
As a simple example, say there is table 'namelist' with column 'names' as char(20). I would like to do something akin to: select namelist.names as mynames, left(mynames,2) as initials; In this example, I could just do left(namelist.names,2), but in more complex cases a value retrieved may have had a more complex logic behind it, e.g., if...
0
3288
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex queries yes or no, I have prepared an example. The example is a database with the following tables: *table person with fields: -persid:...
5
2061
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in total) but sometimes not all the fields will be filled. If a field is empty then the assumption is that no filter will be applied to that field in the...
0
3059
prabirchoudhury
by: prabirchoudhury | last post by:
CRITERIA; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | CritCode | int(4) | NO | PRI | 0 | | | Description | varchar(150) | YES | | NULL | | | CritGroup |...
4
9481
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 the process of migrating the data over to Access 2007 (Windows XP), kind of learning as I go. I’ve managed to import the client records into a...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.