A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Formula and Table Joining in a Query



 
 
Thread Tools Display Modes
  #1  
Old July 11th, 2008, 09:39 PM posted to microsoft.public.access.queries
MichaelR
external usenet poster
 
Posts: 48
Default Formula and Table Joining in a Query

Hi,

I have two tables - one has all of my company sales data with many columns
and the other has a row for each state, rep, product combination. The second
table is just supposed to show which products and in which states each rep is
allowed to sell. So, for example, rep Michael who is allowed to sell products
X, Y, X in NY and NJ, would have six row entries in the table, one for each
possible combination.

I am trying to write a formula (as part of a larger query) that will write
Correct/Incorrect for each sale in the sales data table. If the
rep/state/product combination in the sales table is also in the lookup table
then the formula should return "correct." Otherwise, the formula should
return "incorrect."

I tried to accomplish this by adding a column called Label to the second
table that said "correct" and then left joining the two tables on
rep/state/product. In the query, I wrote, IIF(label"",label,"Incorrect).
Although the formula worked, my resulting table had 470,000 rows even though
my actual sales data table only had 340,000. Does anyone have any idea why
this might be happening? Is there an easier way to accomplish what I'm trying
to do?

Thanks,
Michael
  #2  
Old July 11th, 2008, 10:00 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Formula and Table Joining in a Query

Here [Michael_R-1] is the sales table and [Michael_R] is the lookup for who
can sale what/where.

SELECT [Michael_R-1].*
FROM [Michael_R-1] LEFT JOIN Michael_R ON ([Michael_R-1].Product =
Michael_R.Product) AND ([Michael_R-1].Rep = Michael_R.Rep) AND
([Michael_R-1].State = Michael_R.State)
WHERE (((Michael_R.State) Is Null)) OR (((Michael_R.Rep) Is Null)) OR
(((Michael_R.Product) Is Null));

--
KARL DEWEY
Build a little - Test a little


"MichaelR" wrote:

Hi,

I have two tables - one has all of my company sales data with many columns
and the other has a row for each state, rep, product combination. The second
table is just supposed to show which products and in which states each rep is
allowed to sell. So, for example, rep Michael who is allowed to sell products
X, Y, X in NY and NJ, would have six row entries in the table, one for each
possible combination.

I am trying to write a formula (as part of a larger query) that will write
Correct/Incorrect for each sale in the sales data table. If the
rep/state/product combination in the sales table is also in the lookup table
then the formula should return "correct." Otherwise, the formula should
return "incorrect."

I tried to accomplish this by adding a column called Label to the second
table that said "correct" and then left joining the two tables on
rep/state/product. In the query, I wrote, IIF(label"",label,"Incorrect).
Although the formula worked, my resulting table had 470,000 rows even though
my actual sales data table only had 340,000. Does anyone have any idea why
this might be happening? Is there an easier way to accomplish what I'm trying
to do?

Thanks,
Michael

  #3  
Old July 11th, 2008, 10:10 PM posted to microsoft.public.access.queries
MichaelR
external usenet poster
 
Posts: 48
Default Formula and Table Joining in a Query

Karl, how would I write the "WHERE (((Michael_R.State) Is Null)) OR
(((Michael_R.Rep) Is Null)) OR (((Michael_R.Product) Is Null)); in design
view?

Thanks.

"KARL DEWEY" wrote:

Here [Michael_R-1] is the sales table and [Michael_R] is the lookup for who
can sale what/where.

SELECT [Michael_R-1].*
FROM [Michael_R-1] LEFT JOIN Michael_R ON ([Michael_R-1].Product =
Michael_R.Product) AND ([Michael_R-1].Rep = Michael_R.Rep) AND
([Michael_R-1].State = Michael_R.State)
WHERE (((Michael_R.State) Is Null)) OR (((Michael_R.Rep) Is Null)) OR
(((Michael_R.Product) Is Null));

--
KARL DEWEY
Build a little - Test a little


"MichaelR" wrote:

Hi,

I have two tables - one has all of my company sales data with many columns
and the other has a row for each state, rep, product combination. The second
table is just supposed to show which products and in which states each rep is
allowed to sell. So, for example, rep Michael who is allowed to sell products
X, Y, X in NY and NJ, would have six row entries in the table, one for each
possible combination.

I am trying to write a formula (as part of a larger query) that will write
Correct/Incorrect for each sale in the sales data table. If the
rep/state/product combination in the sales table is also in the lookup table
then the formula should return "correct." Otherwise, the formula should
return "incorrect."

I tried to accomplish this by adding a column called Label to the second
table that said "correct" and then left joining the two tables on
rep/state/product. In the query, I wrote, IIF(label"",label,"Incorrect).
Although the formula worked, my resulting table had 470,000 rows even though
my actual sales data table only had 340,000. Does anyone have any idea why
this might be happening? Is there an easier way to accomplish what I'm trying
to do?

Thanks,
Michael

  #4  
Old July 11th, 2008, 11:03 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Formula and Table Joining in a Query

Put the Is Null on a separate criteria row for each.
--
KARL DEWEY
Build a little - Test a little


"MichaelR" wrote:

Karl, how would I write the "WHERE (((Michael_R.State) Is Null)) OR
(((Michael_R.Rep) Is Null)) OR (((Michael_R.Product) Is Null)); in design
view?

Thanks.

"KARL DEWEY" wrote:

Here [Michael_R-1] is the sales table and [Michael_R] is the lookup for who
can sale what/where.

SELECT [Michael_R-1].*
FROM [Michael_R-1] LEFT JOIN Michael_R ON ([Michael_R-1].Product =
Michael_R.Product) AND ([Michael_R-1].Rep = Michael_R.Rep) AND
([Michael_R-1].State = Michael_R.State)
WHERE (((Michael_R.State) Is Null)) OR (((Michael_R.Rep) Is Null)) OR
(((Michael_R.Product) Is Null));

--
KARL DEWEY
Build a little - Test a little


"MichaelR" wrote:

Hi,

I have two tables - one has all of my company sales data with many columns
and the other has a row for each state, rep, product combination. The second
table is just supposed to show which products and in which states each rep is
allowed to sell. So, for example, rep Michael who is allowed to sell products
X, Y, X in NY and NJ, would have six row entries in the table, one for each
possible combination.

I am trying to write a formula (as part of a larger query) that will write
Correct/Incorrect for each sale in the sales data table. If the
rep/state/product combination in the sales table is also in the lookup table
then the formula should return "correct." Otherwise, the formula should
return "incorrect."

I tried to accomplish this by adding a column called Label to the second
table that said "correct" and then left joining the two tables on
rep/state/product. In the query, I wrote, IIF(label"",label,"Incorrect).
Although the formula worked, my resulting table had 470,000 rows even though
my actual sales data table only had 340,000. Does anyone have any idea why
this might be happening? Is there an easier way to accomplish what I'm trying
to do?

Thanks,
Michael

  #5  
Old July 14th, 2008, 03:46 PM posted to microsoft.public.access.queries
MichaelR
external usenet poster
 
Posts: 48
Default Formula and Table Joining in a Query

Karl, I tried to run the query within my query but it returned a blank table.
I think that I might not have explained what I was trying to accomplish as
well as I could have.

What I need this query to do is to make a column in the resulting query
table that says whether each row from the original sales data table was
correctly booked or miscorrectly booked based on whether the sale was in a
state and product that the rep represented.

Thanks and sorry for the confusion. Michael
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.