Solved

Puzzle with a Crosstab Query

Posted on 2011-02-12
7
279 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Normalization of a table 19 71
Should I keep recordsets open? 3 24
Filter a form 8 14
Use .MoveNext in VBA but have it filter criteria 2 12
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

770 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