Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Puzzle with a Crosstab Query

Posted on 2011-02-12
7
Medium Priority
?
285 Views
Last Modified: 2012-05-11
Hi,

I buy products. (tblProducts)
I but them from many suppliers. (tblSuppliers)
The table tblPrices holds the price of each item from the suppliers.

The KEY factor is that any one product could be bought from several suppliers.

The form frmPrices_Crosstab1 displays a grid all the product prices from all suppliers.
E.g. I can buy "Balls" for 888.00 from supplier "Gold Ireland".

There is a flag on the table tbl_Prices called "Use_Price" which will be TRUE if this is the chosen supplier for this particular product.

Problem : How do I show the "Use_Price" flag on the form frmPrices_Crosstab1.


Essentially, I am looking for an easy way to work-around the limitations of the crosstab.
(Possible clue : See the way I combined the product code and description into one field on this form).
DerekImport--2-.zip
0
Comment
Question by:Patrick O'Dea
  • 4
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34879890
not really sure what you are looking for, try this

TRANSFORM Avg(tblPrices.CostPrice) AS AvgOfCostPrice
SELECT tblproducts.productcode & " --> " & tblproducts.description AS Expr1
FROM (tblPrices INNER JOIN tblProducts ON tblPrices.ProductCode = tblProducts.ProductCode) INNER JOIN tblSuppliers ON tblPrices.SupplierID = tblSuppliers.ID
Where tblPrices.Use_Price=True
GROUP BY tblproducts.productcode & " --> " & tblproducts.description
PIVOT tblSuppliers.SupplierName;
0
 

Author Comment

by:Patrick O'Dea
ID: 34879949
Thanks capricorn1,

Not quite what I wanted.
I'll clarify if I can.

I want the crosstab to show all prices from all suppliers.
But since I have flagged one supplier (likely to be the cheapest!) as the one specific supplier for that specific product.

So, I want to see ALL prices (as my form currently shows) but I would like the chosen supplier highlighted somehow (using the crosstab format).





0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34880002
i don't think that will be possible by just using the query.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Patrick O'Dea
ID: 34880026

See SQL below which works in a very crude way.
I linked the two fields "Use_price" and "CostPrice" into one single field.

This way the price chosen is prefixed by a -1  (!).  So for instance a price of 555 is shown as -1555.

Very ugly but it does work.
Do you thinks there is a tidier way based on this logic??



TRANSFORM Avg([use_price] & [CostPrice]) AS Expr3
SELECT [tblproducts].[productcode] & " --> " & [tblproducts].[description] AS Expr1
FROM (tblPrices INNER JOIN tblProducts ON tblPrices.[ProductCode] = tblProducts.ProductCode) INNER JOIN tblSuppliers ON tblPrices.SupplierID = tblSuppliers.ID
GROUP BY [tblproducts].[productcode] & " --> " & [tblproducts].[description]
PIVOT tblSuppliers.[SupplierName];
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 34880204
if for visual use only, try this

TRANSFORM Avg(IIf([use_price]=0,[CostPrice],[use_price]*[CostPrice])) AS Expr3
SELECT [tblproducts].[productcode] & " --> " & [tblproducts].[description] AS Expr1
FROM (tblPrices INNER JOIN tblProducts ON tblPrices.ProductCode = tblProducts.ProductCode) INNER JOIN tblSuppliers ON tblPrices.SupplierID = tblSuppliers.ID
GROUP BY [tblproducts].[productcode] & " --> " & [tblproducts].[description]
PIVOT tblSuppliers.SupplierName;
0
 

Author Comment

by:Patrick O'Dea
ID: 34882506
Thanks again.

Clever
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 34889113
vg
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

824 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