Access 2010:该字段太小,无法接受您尝试添加的数据量而没有DISTINCT

时间:2012-07-10 06:43:35

标签: ms-access ms-access-2010 outer-join

我知道有关此访问错误消息的一些问题,但它们与我的查询不使用DISTINCT关键字无关。

我有两个类似的查询,一个包含信用,另一个包含借方。它们按月和按类别分组。

最终我希望在这两个表上进行完全外连接,以便我可以减去它们以获得每个类别中每个月的结果余额。

然而,Access不允许完全外连接,所以我需要做一个Right OUTER UNION LEFT OUTER NERE。

我现在正尝试在月份和类别ID字段上进行RIGHT OUTER连接。当我在一个字段上执行外连接时,它按预期工作。当我在另一个字段上执行它时,它按预期工作,但当我加入这两个字段时,我得到“字段太小,无法接受您尝试添加的数据量”

表1:

Credits Query

制作人:

SELECT [transactions by category].[categoryid]                    AS CategoryID,
       Format([account transactions].[transaction date], "mm/yy") AS MonthYear,
       Nz(SUM([transactions by category].[amount]), 0)            AS
       [Category Total]
FROM   [transactions by category]
       INNER JOIN [account transactions]
               ON [account transactions].[id] =
                  [transactions by category].[transactionid]
WHERE  [account transactions].[transaction type] <> 8
GROUP  BY Format([account transactions].[transaction date], "mm/yy"),
          [transactions by category].[categoryid]; 

表2:

Debits Table

制作人:

SELECT [transactions by category].[categoryid],
       Format([account transactions].[transaction date], "mm/yy") AS MonthYear,
       Nz(SUM([transactions by category].[amount]), 0)            AS
       [Category Total]
FROM   [transactions by category]
       INNER JOIN [account transactions]
               ON [account transactions].[id] =
                  [transactions by category].[transactionid]
WHERE  [account transactions].[transaction type] = 8
GROUP  BY Format([account transactions].[transaction date], "mm/yy"),
          [transactions by category].[categoryid]; 

正确的加入给了我错误:

SELECT * FROM
  ((SELECT [transactions by category].[categoryid],
           Format([account transactions].[transaction date], "mm/yy") 
              AS MonthYear,
           Nz(SUM([transactions by category].[amount]), 0) AS [Category Total]
    FROM   [transactions by category]
           INNER JOIN [account transactions]
                   ON [account transactions].[id] =
                      [transactions by category].[transactionid]
    WHERE  [account transactions].[transaction type] = 8
    GROUP  BY Format([account transactions].[transaction date], "mm/yy"),
              [transactions by category].[categoryid]) AS [Category Returns]
RIGHT JOIN 
   (SELECT [transactions by category].[categoryid] AS CategoryID,
           Format([account transactions].[transaction date], "mm/yy") 
               AS MonthYear,
           Nz(SUM([transactions by category].[amount]), 0) AS [Category Total]
    FROM   [transactions by category]
           INNER JOIN [account transactions]
                   ON [account transactions].[id] = 
                      [transactions by category].[transactionid]
    WHERE  [account transactions].[transaction type] <> 8
    GROUP  BY Format([account transactions].[transaction date], "mm/yy"),
              [transactions by category].[categoryid]) AS [Category Debits]

ON [Category Returns].[categoryid] = [Category Debits].[categoryid]
   AND [Category Returns].[monthyear] = [Category Debits].[monthyear] ); 

似乎文本字段出现此错误。当我使用Format时,MonthYear字段会变成文本字段吗?即使它仍然只有5个字符长。另外,当我仅加入MonthYear列时,加入工作正常,但只有当我加入两个字段时才会失败。

1 个答案:

答案 0 :(得分:2)

根据您的标记,您使用的是SQL Server作为后端。您遇到的问题不是来自MS Access,而是来自MS Access和SQL Server的组合。该查询将在纯MS Access环境中工作。 (是的,格式确实会转换为文本。)

您可以使用pass-through queries创建使用SQL Server语法运行的查询,因此您可以使用完全外部联接,或者您可以考虑http://weblogs.sqlteam.com/jeffs/archive/2007/04/19/Full-Outer-Joins.aspx

编辑标签重新更改

如果您的某个字段是备注字段,请参阅http://support.microsoft.com/kb/896950。在像这样的复杂查询中,最好将备注字段减少到255或更少。