Solved

Puzzle with a Crosstab Query

Posted on 2011-02-12
7
282 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 500 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

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!

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

751 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