I want maximum period of date range that is overlapping each other and
if the period is not clashing other date ranges than i want it as it is.
I have this table :
CREATE TABLE [dbo].[table1](
[id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[StartDate] [datetime] NOT NULL,
[EndDate] [datetime] NOT NULL
)
And their respective values:
INSERT [dbo].[table1] VALUES ( CAST('2013-11-01 00:00:00.000' AS DateTime), CAST('2013-11-10 00:00:00.000' AS DateTime))
INSERT [dbo].[table1] VALUES ( CAST('2013-11-05 00:00:00.000' AS DateTime), CAST('2013-11-15 00:00:00.000' AS DateTime))
INSERT [dbo].[table1] VALUES ( CAST('2013-11-10 00:00:00.000' AS DateTime), CAST('2013-11-15 00:00:00.000' AS DateTime))
INSERT [dbo].[table1] VALUES ( CAST('2013-11-10 00:00:00.000' AS DateTime), CAST('2013-11-25 00:00:00.000' AS DateTime))
INSERT [dbo].[table1] VALUES ( CAST('2013-11-26 00:00:00.000' AS DateTime), CAST('2013-11-29 00:00:00.000' AS DateTime))
And expected result is :
ID StartDate EndDate
1 1-Nov-2013 25-Nov-2013
2 26-Nov-2013 29-Nov-2013
Thanks in advance.
Manish Insan
Software Developer