Link to home
Start Free TrialLog in
Avatar of Patrick O'Dea
Patrick O'DeaFlag for Ireland

asked on

Puzzle with a Crosstab Query

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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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;
Avatar of Patrick O'Dea

ASKER

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).





i don't think that will be possible by just using the query.

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];
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again.

Clever
vg