[英]Syntax on SQL statement with multiple conditions in WHERE clause
I am getting a run time 3075 issue on the following SQL string below. 我在下面的SQL字符串上遇到运行时3075问题。 Is it possible I am missing parentheses? 我有可能错过括号吗?
sql_get =
"SELECT [tblCompetency02].[HighLevelObjective],
[tblCompetency04].[Self],
[tblCompetency04].[SelfSpecialLanguage],
[tblCompetency04].[SelfChecklist],
[tblCompetency04].[Team],
[tblCompetency04].[TeamSpecialLanguage],
[tblCompetency04].[TeamChecklist],
[tblCompetency04].[Organisation],
[tblCompetency04].[OrganisationSpecialLanguage],
[tblCompetency04].[OrganisationChecklist],
[tblCompetency02].[Competency]
FROM [tblCompetency04]
INNER JOIN [tblCompetency02]
ON [tblCompetency04].[HighLevelObjective] = [tblCompetency02].[ID]
WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>"""
Form_frmStaticDataSkills02.Form.RecordSource = sql_get
Examine the WHERE
clause of the statement your code creates. 检查代码创建的语句的WHERE
子句。
Here's an Immediate window session: 这是一个立即窗口会话:
sql_get = "WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>"""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>" or [tblcompetency04].[team]<>" or [tblcompetency04].[organisation]<>"
Notice there is just one double quote character in each of these cases: <>"
请注意,在每种情况下只有一个双引号字符: <>"
If you want to have double quotes inside the string, use two to get one ... 如果你想在字符串中有双引号,请使用两个来获得一个...
sql_get = "WHERE [tblcompetency04].[self]<>"""" or [tblcompetency04].[team]<>"""" or [tblcompetency04].[organisation]<>"""""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>""
But I think it is less confusing and less error-prone to use single quotes inside the string ... 但我认为在字符串中使用单引号不那么容易混淆,也不容易出错...
sql_get = "WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''"
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.