0

I know there are a couple of questions regarding this Access Error message, but they are not related in that my query doesn't use the DISTINCT Key word.

I have two similar queries, one contains credits and the other contains debits. They are grouped by month and by category.

Ultimately I want a full outer join on these two tables so that I can subtract them to get a resulting balance for each month in each category.

However Access doesn't allow full outer joins so I need to do a Right OUTER UNION LEFT OUTER WHERE Null.

I am now trying to do the RIGHT OUTER join on the Month and Category ID fields. When I do the outer join on one field, it works as expected. When I do it on the other field it works as expected but when I join on both fields I get "The field is too small to accept the amount of data you attempted to add"

Table 1:

Credits Query

Produced by:

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]; 

Table 2:

Debits Table

Produced by:

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]; 

The Right Join that gives me the error:

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] ); 

It seems like this error occurs with text fields. When I use Format does the MonthYear field become a text field? Even still it is only 5 characters long. Plus the join works when I join only on the MonthYear columns, but only fails when I join on both fields.

ajon
  • 7,868
  • 11
  • 48
  • 86

1 Answers1

2

You are using SQL server as your back-end, according to your tags. The problem you are experiencing is not from MS Access, but from a combination of MS Access and SQL Server. The query would work in a purely MS Access environment. (Yes, format does convert to text.)

You can use pass-through queries to create a query that runs using SQL Server syntax and therefore you can use a full outer join, or you may wish to consider http://weblogs.sqlteam.com/jeffs/archive/2007/04/19/Full-Outer-Joins.aspx

EDIT re change of tags

If one of your fields is a memo field, see http://support.microsoft.com/kb/896950. In a complex query like this, it is best to trim memo fields down to 255 or less.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
  • +1 If all of these tables reside on the SQL Server then I would go with Remou's second option if available to you. It should give better performance also than an Access query on linked SQL Server tables. – Matt Donnan Jul 10 '12 at 14:21
  • @MattDonnan There is only one option, the query will not work in a mixed environment. – Fionnuala Jul 10 '12 at 15:59
  • This is not SQL Server. I don't know what I said to indicate that, but this is a strictly MS Access 2007 database. I'm still looking into that link to see if that will be a good solution though. – ajon Jul 10 '12 at 20:45
  • 1
    @user1068058 Your tags say SQL Server. I tested with a very similar query in MS Access (ie with Jet/ACE) and it works for me. – Fionnuala Jul 10 '12 at 20:48