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

白昼怎懂夜的黑 提交于 2021-01-27 20:35:16

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/937797/how-do-you-do-a-crosstab-query-in-access-with-a-fixed-amount-of-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!