0

I have a table in my SQL Server like this:

ID Tblcd TblNo  Location    TableType   StartDate   EndDate
---------------------------------------------------------------
2   B      4      2B4          M        2/5/2014    4/6/2016
2   B      4      2B4          M        4/7/2017    NULL
2   B      4      2B4          K        3/4/2016    NULL
3   A      3      3A3          L        2/7/2018    7/4/2018
3   A      3      3A3          L        2/5/2018    NULL
1   C      5      1C5          N        2/4/2011    NULL
1   B      4      1B4          M        8/9/2015    3/5/2017

I want to identify the row which has StartDate as 2/5/2018 which is actually overlapping with the previous entry

Tried using the below query, but unable to find the second entry. What am I missing here.

SELECT
    A.Id AS AId,
    B.Id AS BId,
    A.StartDate AS AStartDate,
    A.EndDate AS AEndDate,
    B.StartDate AS BStartDate,
    B.EndDate AS BEndDate
FROM    
    dbo.TableDates AS a
INNER JOIN  
    dbo.TableDates AS b ON (b.Id = a.Id AND b.TblCd = a.TblCd AND b.TblNo = a.TblNo)
WHERE   
    a.StartDate <= b.EndDate
    AND a.EndDate >= b.StartDate
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Andy
  • 1
  • 1

0 Answers0