0

我有一个连接到 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,但需要日期的三个参数是抛出错误的参数。如果数据类型相同,可能导致此问题的原因是什么?

4

1 回答 1

0

看起来可以通过将 excel 文件中的日期更改为文本字段而不是日期来解决此问题。这解决了这个问题。

于 2014-12-11T04:07:53.820 回答