Detect overlapping date ranges from the same table

前端 未结 9 1162
甜味超标
甜味超标 2020-12-01 04:26

I have a table with the following data

PKey  Start       End         Type
====  =====       ===         ====
01    01/01/2010  14/01/2010  S
02    15/01/2010         


        
9条回答
  •  不知归路
    2020-12-01 04:50

    I had to do a very similar thing for to stop duplicate holiday being entered into a table. it was in access and written to a temptable on input so had to query it in VBA SQL:

     stCommandText = "SELECT " _
                        & "* " _
                        & "FROM " _
                        & "TableName a, " _
                        & "TableName b " _
                        & "WHERE " _
                        & "a.ID = b.ID " _
                        & "AND a.Startdate >= b.Startdate AND a.StartDate <= b.EndDate " _
                        & "AND a.AutoNo <> b.AutoNo "
    

提交回复
热议问题