Date: Tue, 16 Feb 2016 18:42:00 +0000
Subject: RE: [MS_AccessPros] Crosstab as data source for subsequent queries
John, brilliant. I'm going to remember this one.
You can force the column names to be constant by adding an IN clause to the SQL.
TRANSFORM Sum([Order Details].Quantity) AS SumOfQuantity
SELECT Products.[Product Name]
FROM Products INNER JOIN (Customers RIGHT JOIN (Orders INNER JOIN [Order Details] ON Orders.[Order ID] = [Order Details].[Order ID]) ON Customers.ID = Orders.[Customer ID]) ON Products.ID = [Order Details].[Product ID]
GROUP BY Products.[Product Name]
PIVOT Customers.Company In ("Company A","Company B","Company C");
John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
I find myself needing to work with crosstabs lately and needing to use the output of a crosstab as the data source for another query. Crosstab field names are dynamic. By that I mean that the field names in the query result depend on the data being transformed. So the field list will have differing numbers of fields from run to run. I am currently managing the output by using VBA to generate TRANSFORM SQL at runtime and then replace the SQL in a querydef. This provides me with the source for further downstream processing that is responsive to current data and user request.
Can anyone share their insight into using crosstabs especially as the source for further querying?
This email (and all attachments) is for the sole use of the intended recipient(s) and may contain privileged and/or proprietary information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Posted by: Steve Conklin <email@example.com>
|Reply via web post||•||Reply to sender||•||Reply to group||•||Start a New Topic||•||Messages in this topic (5)|