简体   繁体   English

在SELECT查询中MS Access“此记录集不可更新”

[英]MS Access “This recordset is not updatable” in a SELECT query

I'm stumped regarding this message MS Access is giving me. 关于MS Access给我的这条消息,我很难过。

I am trying to run a SELECT query, with two sub-queries within it. 我正在尝试运行SELECT查询,其中包含两个子查询。 All tables are local. 所有表都是本地的。

Could someone please explain to me why the following code is returning this error? 有人可以向我解释为什么以下代码返回此错误?

SELECT S.SKU, S.Date, S.[Order No], P.WSP, P.Average_Cost, S.[Item Status]
FROM [Item Detail Temp] AS S, [FD Worksheets Temp] AS P
WHERE [P].[SKU]=[S].[SKU] AND [P].[Date to use]=(SELECT MIN(P2.[Date to use])
                         FROM   [FD Worksheets Temp] P2
                         WHERE  P2.[SKU] = S.[SKU]
                         AND    P2.[Date to use] >= S.[Date]);

Giving it a google hasn't particularly helped. 给它谷歌并没有特别的帮助。 I have Macros enabled in security to make sure that wasnt it, and from what I can tell I dont have any sort of Grouping in the code above that could cause the error? 我在安全性中启用了宏以确保它不存在,并且从我可以告诉我在上面的代码中没有任何可能导致错误的分组?

Additionally, I believe the code does work just fine, but the whole time the loading bar is up that message is displayed in the bottom left corner of the screen. 此外,我相信代码确实可以正常工作,但是加载栏的整个时间都是在屏幕的左下角显示消息。 It also runs incredibly slow, and i'm sure i have run this query in the past without that message showing up, and also much quicker than it is currently. 它的运行速度也非常慢,而且我确信我在过去运行此查询时没有显示该消息,并且比目前更快。

Many thanks 非常感谢

EDIT: After looking a bit more, I have found a few possible reasons: 编辑:看了一下之后,我发现了一些可能的原因:

"- It uses First(), Sum(), Max(), Count(), etc. in the SELECT clause. Queries that aggregate records are read-only. - There is a MIN() function, could that be causing it? “ - 它在SELECT子句中使用First(),Sum(),Max(),Count()等。聚合记录的查询是只读的。 - 有一个MIN()函数,可能导致它?

- It has a subquery in the SELECT clause. - 它在SELECT子句中有一个子查询。 Uncheck the Show box under your subquery, or use a domain aggregation function instead." 取消选中子查询下的“显示”框,或使用域聚合功能代替。“

- The fields in a JOIN are not indexed correctly: there is no primary key or unique index on the JOINed fields. - JOIN中的字段未正确编制索引:JOINed字段上没有主键或唯一索引。 There are no Unique Key fields, could that be the reason? 没有唯一键字段,可能是这个原因吗?

JOIN your table sources and use the domain aggregate function, DMin , to make your query updateable. JOIN表源并使用域聚合函数DMin使您的查询可更新。

FROM
    [Item Detail Temp] AS S
    INNER JOIN [FD Worksheets Temp] AS P
    ON [P].[SKU]=[S].[SKU]
WHERE
    [P].[Date to use]=
        DMin
            (
                "[Date to use]",
                "FD Worksheets Temp",
                "[SKU] = " & S.[SKU] & " AND [Date to use] >= " & Format(S.[Date], "\#yyyy-m-d\#")
            );

Hans, I noticed you deleted you comment. 汉斯,我注意到你删除了你的评论。 I got it just in time, and it works perfectly. 我及时得到它,它完美无缺。 The query now runs in less than a second, compared to the 5-10 mins it was before. 现在查询运行时间不到一秒,而之前的查询时间为5-10分钟。

I managed using the following: 我使用以下方法管理:

SELECT S.SKU, S.Date, S.[Order No], P.WSP, P.Average_Cost, S.[Item Status]
FROM [Item Detail Temp] AS S, [FD Worksheets Temp] AS P
WHERE
        [P].[SKU]=[S].[SKU] 
    AND [P].[Date to use]=
            DMin
                (
                    "[Date to use]",
                    "FD Worksheets Temp",
                    "[SKU] = " & S.[SKU] & " AND [Date to use] >= " & Format(S.[Date], "\#yyyy-m-d\#")
            );

您的查询包含聚合函数MIN ,表应该使用JOIN子句连接,连接列也应该被索引,详细信息表应该使用具有唯一索引的列连接,通常是它的主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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