我有一个连接到Excel仪表板的Access数据库。我有一个执行任务的查询,但在完成查询之前需要将一些日期设置为条件。我使用参数指向仪表板中的几个点以检索查询正确执行所需的日期。
“访问权限”字段中的日期设置为date/time
,信息中心中的日期也设置为date/time
。出于某种原因,当我尝试运行查询时,它会说[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression]
。正如我前面提到的,它所指向的Excel位置以及它所连接的Access字段都设置为相同的类型。
如果我将日期硬编码到SQL中,则查询运行完美,在参数弹出窗口中输入时也会正确运行。唯一不行的是,当我尝试将其指向仪表板中的某个日期时,会导致上面的错误消息。这是我的查询代码:
SELECT tbl_Master_Phone.ID,
tbl_Master_Bill_Cycle_Date.Bill_Cycle_Date,
tbl_Master_ECPD.Client_ID,
tbl_Master_Client.Client_Name,
tbl_Master_ECPD.ECPD_ID,
tbl_Master_Account.Account_Number,
tbl_Master_Phone.Wireless_Number,
tbl_Master_Username.User_Name,
tbl_Master_Cost_Center.Cost_Center,
Max(tbl_Inventory.Bill_Cycle_Date) ,
tbl_Master_Device.Device_Model,
tbl_Master_Device.Device_Type,
tbl_Inventory.Device_ID,
tbl_Inventory.SIM,
tbl_Inventory.Contract_Activate_Date,
tbl_Inventory.Contract_End_Date,
tbl_Inventory.Upgrade_Eligibility_Date
FROM tbl_Master_Username
INNER JOIN ((tbl_Master_Client
INNER JOIN ((tbl_Master_Account
INNER JOIN tbl_Master_ECPD
ON tbl_Master_Account.ECPD_ID = tbl_Master_ECPD.ID)
INNER JOIN (tbl_Master_Device
INNER JOIN (tbl_Master_Phone
INNER JOIN tbl_Inventory
ON tbl_Master_Phone.ID = tbl_Inventory.Wireless_Number)
ON tbl_Master_Device.ID = tbl_Inventory.Device_Model)
ON tbl_Master_Account.ID = tbl_Inventory.Account_Number)
ON tbl_Master_Client.ID = tbl_Master_ECPD.Client_ID)
INNER JOIN (tbl_Master_Bill_Cycle_Date
INNER JOIN (tbl_Master_Cost_Center
INNER JOIN tbl_Phone_Details
ON tbl_Master_Cost_Center.ID = tbl_Phone_Details.Cost_Center)
ON tbl_Master_Bill_Cycle_Date.Bill_Cycle_Date = tbl_Phone_Details.Bill_Cycle_Date)
ON tbl_Master_Phone.ID = tbl_Phone_Details.Wireless_Number)
ON tbl_Master_Username.ID = tbl_Phone_Details.Username
Where ((tbl_Inventory.Bill_Cycle_Date<=?))
GROUP BY tbl_Master_Phone.ID,
tbl_Master_Bill_Cycle_Date.Bill_Cycle_Date,
tbl_Master_ECPD.Client_ID,
tbl_Master_Client.Client_Name,
tbl_Master_ECPD.ECPD_ID,
tbl_Master_Account.Account_Number,
tbl_Master_Phone.Wireless_Number,
tbl_Master_Username.User_Name,
tbl_Master_Cost_Center.Cost_Center,
tbl_Master_Device.Device_Model,
tbl_Master_Device.Device_Type,
tbl_Inventory.Device_ID,
tbl_Inventory.SIM,
tbl_Inventory.Contract_Activate_Date,
tbl_Inventory.Contract_End_Date,
tbl_Inventory.Upgrade_Eligibility_Date
HAVING ((tbl_Master_Bill_Cycle_Date.Bill_Cycle_Date>=?)
AND (tbl_Master_ECPD.Client_ID=?)
AND (tbl_Master_Bill_Cycle_Date.Bill_Cycle_Date<=?));
如您所见,在WHERE
语句之后立即设置参数,在HAVING
之后设置三个参数。 HAVING
之后的第二个参数工作正常,但需要日期的三个参数是抛出错误的参数。如果数据类型相同,可能导致此问题的原因是什么?
答案 0 :(得分:0)
看起来可以通过将excel文件中的日期更改为文本字段而不是日期来解决问题。这解决了这个问题。