Since you dont know how many words there are in each message (I'll also assume that each Message can have a variable number of words), you probably have to do this in a procedural fashion.
I can show the pseudo-code/logic but I do not know Access well enough to tell you it can be done. It could be done in ORACLE or SQL-Sever using procedures or a recursive function.
Procedurally:
generate a cursor of all Messages records
ordered by MessageID, WordNumber;
get first MessageID, Word;
While cursor of records is not done, LOOP:
While MessageID has not changed, LOOP:
MsgString := MsgString + Word;
get next MessageID, Word;
End-While
Print MsgStrng;
End-While
Recursively:
-- assumes word number is sequential and no gaps
For each unique MessageID LOOP
call function MakeString(MessageID,1,'');
End-Loop
Function MakeString (@MsgID, @WordNum, @MsgStr)
Get Word from Messages
where MessageID = @MsgID
and WordNumber = @WordNum;
If no record then return @MsgStr; -- exit cond
else
@MsgStr := @MsgStr + Word;
-- make recursive call
MakeString(@MsgId, @WordNum+1, @MsgStr);
End-Function
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.