VBA - 在Oracle DB上将日期作为变量的SQL查询

时间:2017-02-08 16:42:33

标签: sql oracle vba variables

我在VBA中执行每个日期选择的SQL查询。一切正常,直到我指定日期,如下面的代码:

conn.Open dbConnectStr

StartDate = "01/01/2015"

SQL_String = "SELECT * FROM database " & _
             "WHERE date BETWEEN to_date('01/01/2015','dd/mm/yyyy') and to_date('31/12/2016','dd/mm/yyyy')"

recset.Close
conn.Close

但是,当我输入变量而不是日期时,我得到错误multiple-step operation completed with one or more errors. Check each status values.

conn.Open dbConnectStr

StartDate = "01/01/2015"
EndDate = "31/12/2016"

SQL_String = "SELECT * FROM database " & _
             "WHERE date BETWEEN to_date('" & StartDate & "','dd/mm/yyyy') and to_date('" & EndDate & "','dd/mm/yyyy')"

recset.Close
conn.Close

任何人都可以建议如何进行?

0 个答案:

没有答案