The Access database engine normally determines uniqueness of text ('String') data using only the first 255 characters and that is why DISTINCT
and GROUP BY
will truncate.
This suggestion is a bit long winded but it does work: split the MEMO
into chunks of 255 characters, do use DISTINCT
on the chunks, then concatenate them back together again e.g. (Access database engine ANSI-92 Query Mode syntax i.e. parens for subqueries):
SELECT DT2.MyMemoCol_1 & DT2.MyMemoCol_2 AS MyMemoCol
FROM (
SELECT DISTINCT DT1.MyMemoCol_1, DT1.MyMemoCol_2
FROM (
SELECT MID(MyMemoCol, 1, 255) AS MyMemoCol_1,
MID(MyMemoCol, 256, 255) AS MyMemoCol_2
FROM Test1
) AS DT1
) AS DT2;
A comment has been posted:
Breaking the memo down in to
255-character chunks is entirely
unnecessary. You can simply sort on
Left(MyMemoCol, 8192) or some other
appropriately chosen value for the
field length returned.
Well, in my testing this doesn't work at all. Quick repro:
CREATE TABLE Test1 (MyMemoCol MEMO NOT NULL);
INSERT INTO Test1 (MyMemoCol) VALUES (STRING(300, 'A'));
INSERT INTO Test1 (MyMemoCol) VALUES (STRING(300, 'A') & STRING(5, 'X'));
INSERT INTO Test1 (MyMemoCol) VALUES (STRING(300, 'A'));
SELECT LEFT$(MyMemoCol, 8192)
FROM Test1
GROUP
BY LEFT$(MyMemoCol, 8192);
Tested using the SQL view of a Access2007 .accdb ACE engine Query object in SQL-92 Query Mode, the query returns a single row (incorrect) whose value has been truncated at 255 characters (incorrect).
The earlier 'chunking' query returns two rows (correct) without truncation (correct).