I have been searching for a solution for days now but could not find anything anywhere. I have Excel interacting with an Access Database. The following query works in Access:
SELECT DISTINCT A.Timestamp, A.Identifier, A.Remarks, A.ActiveIndicator,
A.S4PDate, B.Timestamp, B.Identifier, B.Remarks, B.ActiveIndicator, B.S4PDate
FROM AAEPData AS A INNER JOIN AAEPData AS B ON A.Identifier = B.Identifier
WHERE (((A.Timestamp = '20131028' AND B.Timestamp = '20131014'))
AND ((datediff('d', A.S4PDate, B.S4PDate)) <> 0))
ORDER BY A.Identifier;
Problem is how to convert this to "VBA-SQL". It should look something like this but I am having trouble with the datediff part of it. How do I handover the interval in days correctly? Here is my VBA code:
sql = "SELECT DISTINCT A.Identifier, A.Remarks, A.ActiveIndicator, A.S4PDate,"
sql = sql & " B.Identifier, B.Remarks, B.ActiveIndicator, B.S4PDate "
sql = sql & "FROM AAEPData AS A "
sql = sql & "INNER JOIN AAEPData AS B ON ((A.Identifier = B.Identifier))"
sql = sql & "WHERE (((A.Timestamp = '20131028' AND B.Timestamp = '20131014')) "
sql = sql & "AND (Datediff('d', A.S4PDate, B.S4PDate) <> 0))) "
sql = sql & "ORDER BY B.Identifier ASC;"
When I do it like this it does not return values but does also not give an error. And I definetly do have changes in the date values S4PDate that I am querying for. Any ideas? Your help is really very much appreciated. Thanks.