Это будет:
Where Table2.Service_Date <= DateAdd("m", -6, Table1.Service_Date)
или:
Where DateAdd("m", 6, Table2.Service_Date) <= Table1.Service_Date
Что выбрать, зависит от того, как обрабатывать даты ультимо - 28, 29,30 и 31.
Если ни один из них не подходит, используйте эту функцию:
Public Function DateAddMonth( _
ByVal datDate As Date, _
Optional ByVal intIncrement As Integer = 1, _
Optional ByVal booLeapYearIgnore As Boolean = True) _
As Date
' Add intIncrement number of months to datDate.
' If datDate is ultimo, return date will also be ultimo.
'
' 1999-10-21, Gustav Brock, Cactus Data ApS, Copenhagen
Dim datDateNext As Date
Dim booUltimo As Boolean
' No specific error handling.
On Error Resume Next
' Add one day.
datDateNext = DateAdd("d", 1, datDate)
' If datDate is ultimo, next day will be the first of the next month.
booUltimo = (Day(datDateNext) = 1)
If (Not booUltimo) And booLeapYearIgnore Then
' Regard February 28 as ultimo also for leap years.
If (Month(datDate) = 2) And (Day(datDate) = 28) Then
' Add one more day.
datDateNext = DateAdd("d", 1, datDateNext)
booUltimo = True
End If
End If
If booUltimo Then
' Add intIncrement number of months to the first of next month.
datDateNext = DateAdd("m", intIncrement, datDateNext)
' Decrement one day.
' As datDate is ultimo, the month will be decremented too.
datDateNext = DateAdd("d", -1, datDateNext)
Else
' Add intIncrement number of months to datDate.
datDateNext = DateAdd("m", intIncrement, datDate)
End If
DateAddMonth = datDateNext
End Function
и любую из них:
Where Table2.Service_Date <= DateAddMonth(Table1.Service_Date, -6)
Where DateAddMonth(Table2.Service_Date, 6) <= Table1.Service_Date