Access(2013) SQL
I am using ConcatRelated()\Dlist (sometimes I refer to Visual Objects that are sourced) to handle a few task with the table below. I can combine data based on a matching key though what i would like to do is combine data based on a matching key and a value that i would use to determine which record is newest. This way the old row gets abandoned and the new row receives the Concat.
What I can do.
Table Main
Ticket | Name | Code2 | LastHop |
------------------------------------------------------
DBC123456 James 10101010 Mexico
DBC123457 James 10101010 Texas
DBC123459 James 10101010 Texas
DBC123457 Mike 10101011 Texas
DBC123459 Mike 10101011 Virginia
OutPut
Table Main
Ticket | Name | Code2 | LastHop |
---------------------------------------------------------------------------
DBC123456,DBC123457,DBC123458 James 10101010 Mexico
DBC123457,DBC123459 Mike 10101011 Texas
What I want to do 'Find duplicate Code2 'Remove DBC from respective TicketNumber 'Compare the 6 digits from the now stripped ticket to see which one is higher 'Keep the highest ones row information and add all the "OLD" Ticket numbers to the Highest ones
This way I always have the most up to date data and a track of the old Ticket Numbers
I.E
Ticket | Name | Code2 | LastHop |
--------------------------------------------------------------------------
DBC123459,DBC123456,DBC123457 James 10101010 Texas
DBC123459,DBC123457 Mike 10101011 Virginia
Current Code
SELECT
sub.[Name],
sub.Code2,
sub.LastHop,
DList("Ticket",
"Query3",
"[Code2] = '" & sub.[Code2] & "'",
"Ticket")
AS Ticket
FROM
(SELECT
q.[Name],
q.Code2,
q.LastHop
FROM Query3 AS q
GROUP BY
q.[Name],
q.Code2,
q.LastHop
) AS sub
ORDER BY
sub.Code2;