A few days ago I asked a question about SO regarding help for a recursive query .
The problem with this question is: "How to get a history of Person appointments."
Now I have a problem like this, but it should answer a slightly different question:
How to get an Appointment history?
For example, if an appointment with identifier = 5 was delayed once, and it was a delay in another meeting, how can I get the following result?
AppointmentID PrevAppointmentID
----------------- ----------------------
1 NULL
5 1
12 5
thanks for the help
Update
These scripts will help you create a table for your tests.
CREATE TABLE [dbo].[Appointments](
[AppointmentID] [int] IDENTITY(1,1) NOT NULL,
[IssueID] [int] NOT NULL,
[Location] [varchar](255) NOT NULL,
[Description] [varchar](255) NOT NULL,
[AppointmentDate] [datetime] NOT NULL,
[AppointmentHour] [datetime] NOT NULL,
[Done] [bit] NOT NULL,
[PrevAppointmentID] [int] NULL,
CONSTRAINT [PK_Appointments] PRIMARY KEY CLUSTERED
(
[AppointmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
source
share