不确定如何制定此查询

时间:2013-07-22 09:45:47

标签: sql vba ms-access

我正在使用vba在访问中运行查询。

这是我插入变量的查询:

SQL = "SELECT * INTO " & _
strNEW & _
" FROM tblTotaalVerlies WHERE 'Filename' LIKE *\" & _
strNEW & _
"\*;"

当使用Debug.Print(SQL)时,我给出了以下查询:

SELECT * INTO 1300 FROM tblTotaalVerlies WHERE 'Filename' LIKE *\1300\*

我在此查询中尝试了多种变体,例如:

SELECT * INTO 1300 FROM tblTotaalVerlies WHERE 'Filename' LIKE *\1300\*;
SELECT * INTO 1300 FROM tblTotaalVerlies WHERE 'Filename' LIKE *\1300\*
SELECT * INTO 1300 FROM tblTotaalVerlies WHERE Filename LIKE %\1300\*%;

并且没有工作。启动此查询的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

SQL = "SELECT * INTO " & _
strNEW & _
" FROM tblTotaalVerlies WHERE [Filename] LIKE '%" & _
strNEW & _
"%';"

答案 1 :(得分:1)

filename是sql reserved word

使用像[FileName]这样的括号覆盖您的文件名,如下所示

SQL = "SELECT * INTO " & _
strNEW & _
" FROM tblTotaalVerlies WHERE [Filename] LIKE *\" & _
strNEW & _
"\*;"