CREATE TABLE [dbo].[EligInput](
[ID] [float] NULL,
[EffectiveDate] [datetime] NULL,
[StratDate] [datetime] NULL,
[EndDate] [datetime] NULL,
[Status] nvarchar NULL
) ON [PRIMARY]
GO
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (131333186, CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-09-30T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (131333186, CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-10-01T00:00:00.000' AS DateTime), CAST(N'2022-12-31T00:00:00.000' AS DateTime), N'D')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (131333186, CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-03-31T00:00:00.000' AS DateTime), N'D')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (157499166, CAST(N'2012-01-01T00:00:00.000' AS DateTime), CAST(N'2022-01-01T00:00:00.000' AS DateTime), CAST(N'2022-03-31T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (157499166, CAST(N'2012-01-01T00:00:00.000' AS DateTime), CAST(N'2022-04-01T00:00:00.000' AS DateTime), CAST(N'2022-06-30T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (157499166, CAST(N'2012-01-01T00:00:00.000' AS DateTime), CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-09-30T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (157499166, CAST(N'2012-01-01T00:00:00.000' AS DateTime), CAST(N'2022-10-01T00:00:00.000' AS DateTime), CAST(N'2022-12-31T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (157499166, CAST(N'2012-01-01T00:00:00.000' AS DateTime), CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-03-31T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (185935730, CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-09-30T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (185935730, CAST(N'2022-07-01T00:00:00.000' AS DateTime), CAST(N'2022-10-01T00:00:00.000' AS DateTime), CAST(N'2022-12-31T00:00:00.000' AS DateTime), N'D')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (185935730, CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-03-31T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (187950850, CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-03-31T00:00:00.000' AS DateTime), N'A')
INSERT [dbo].[EligInput] ([ID], [EffectiveDate], [StratDate], [EndDate], [Status]) VALUES (230389221, CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-01-01T00:00:00.000' AS DateTime), CAST(N'2023-03-31T00:00:00.000' AS DateTime), N'A')
GO
Checking continuous Eligibility, output should be like this. If a ID has continous Eligibility, it should be part of o/p if not it should be ignored. If an ID is inactive and reenrolled it should be picked with latest Eligibility date
--output
ID EffectiveDate
157499166 2012-01-01
185935730 2023-01-01
185935730 2023-01-01
187950850 2023-01-01
230389221 2011-12-01