I have a table which holds a list of criminal charges.These charges can be substituted.. for example, if a chap has been charged with assault but during the trial the victim dies, so the charge gets substituted to murder.
We have a Substitution table, which holds a From_Offence, and a To_Offence. When the charge is substituted, we create a new charge, and then in the substitution table, record the From ID, and then new To_Id.
CREATE TABLE [dbo].[ijis_court_item_association](
[ijis_court_item_association_id] [int] IDENTITY(1,1) NOT NULL,
[from_ijis_court_item_id] [int] NOT NULL,
[to_ijis_court_item_id] [int] NOT NULL
)
A charge can be substituted many times. So, Charge 1 became Charge 2, but then later Charge 3. And then maybe charge 3 becomes charge 4.
You would have:
FROMID TOID
1 2
2 3
3 4
The requirement is to return a list of charge IDs based on a current charge ID.
So, in english, the developer will pass me ChargeID:4, and I need to return the history of that charge (including it's self). And my result set would be:
4
3
2
1
I can maybe do a function, GetPreviousChargeId, and then somehow recursivly do something? But, I was hoping there might be a smart way to accomplish this.
Hopefully there is a way.