I have a SQL Server linked table in Access and I am trying to query to extract from a certain date or data ranges (i.e. < 01/31/2017
, for example). I tried in the criteria in Access design mode, the following: < #01/31/2017#
but it is not comparing correctly.
The field in the SQL server table is datetime data type, I formatted it in Access as Short Date in the properties in design mode.
SELECT dbo_LicensesLiveViewWithRevenue.BAN,
dbo_LicensesLiveViewWithRevenue.PTN,
dbo_LicensesLiveViewWithRevenue.SOC,
dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn,
Format([DeactivationDate],"Short Date") AS DeactOn,
dbo_LicensesLiveViewWithRevenue.RetailPrice,
dbo_LicensesLiveViewWithRevenue.WholeSalePrice,
dbo_LicensesLiveViewWithRevenue.AccountID
FROM dbo_LicensesLiveViewWithRevenue
WHERE (((dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn)< #2017/01/31#)) ORDER BY dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn;
I also tried the query with passing the dates as parameters from a form, with no luck.
SELECT dbo_LicensesLiveViewWithRevenue.BAN,
dbo_LicensesLiveViewWithRevenue.PTN,
dbo_LicensesLiveViewWithRevenue.SOC,
dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn,
Format([DeactivationDate],"Short Date") AS DeactOn,
dbo_LicensesLiveViewWithRevenue.RetailPrice,
dbo_LicensesLiveViewWithRevenue.WholeSalePrice,
dbo_LicensesLiveViewWithRevenue.AccountID
FROM dbo_LicensesLiveViewWithRevenue
WHERE (((dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn)<[Forms]![MainForm]![EndDate]));
The results:
When I run the query directly in SQL server is giving me the correct records with correct dates (in SQL the dates are < '20170131'). In Access I have the same count of records but the dates are showing wrong as in the result pictures.