August 15, 2022 at 3:45 pm
Hi. Looking for someone to help with a query I'm tring to run.
I have a table with thousands of rows and need to find all records referenced by one another by a column
The table looks like the following:
ID Barcode CreateDate OldBarcode
1 101 8/10/2022 NULL
2 102 8/10/2022 NULL
3 103 8/12/2022 102
4 104 8/13/2022 103
I need to be able to get the first date of the original row where the 102 barcode was created. Barcode 103 replaced it on one day, then barcode 104 replaced that one. So I wanted to get to the original barcode. There are other instancnes of this in the same table, so I'd like to be able to get back to that first barcode number for all the rows.
Hopefully this makes sense.
August 15, 2022 at 7:07 pm
So.. just to be sure from your example data...
101 has never been changed.
102 was replaced by 103 which was replaced by 104.
Is that correct?
If so, a hierarchical recursive CTE (rCTE) would be the easy thing to do.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 16, 2022 at 5:58 am
This was removed by the editor as SPAM
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply