简体   繁体   中英

How do you do a crosstab query in Access with a fixed amount of columns

I want to pull data with an MS Access crosstab query so I can bind it to a report. When I load the page I get a Run-time error'3637': Cannot use the crosstab of a non-fixed column as a subquery.

I would like a way to get back a fixed grid when I run the query and if the cell is null display a zero.

Subquery? That's one of my weaknesses when it comes to Access so I can't help you there. I'd suggest posting the SQL of the query though so others can take a look. Also what happens when you run the query?

The following is a query that I'm using to give me costs for the last ten years for a given unit. TRANSFORM Sum(ServiceRecords.srTotalCost) AS AnnualCost SELECT ServiceRecords.srEquipmentID FROM ServiceRecords GROUP BY ServiceRecords.srEquipmentID PIVOT "C" & DateDiff("yyyy",[srServiceDate],Date()) In ("C9","C8","C7","C6","C5","C4","C3","C2","C1","C0");

The trick is after the PIVOT. As I want the last ten years worth of data the "C" & DateDiff portion sets up a string variable call C0 to C9. The portion after the In tells which column to stuff things into.

Another query which pulls in data about the Equipment calls this query. The term we generally use for such is stacked queries.

If this isn't enough to get you going please indicate what type of data you are trying to create a cross tab.

Fellow Access MVP, Allen Browne has a good page on this topic. Crosstab query techniques

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM