Selasa, 16 Februari 2016

RE: [MS_AccessPros] Crosstab as data source for subsequent queries


John, brilliant.  I'm going to remember this one.


I hope. 




From: []
Sent: Tuesday, February 16, 2016 10:52 AM
Subject: Re: [MS_AccessPros] Crosstab as data source for subsequent queries




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 

(Paris, France)




On Feb 16, 2016, at 5:40 PM, 'Glenn Lloyd' [MS_Access_Professionals] <> wrote:


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: Liz Ravenwood <>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)



Tidak ada komentar:

Posting Komentar