WHERE 子句中具有多个条件的 SQL 语句的语法
Syntax on SQL statement with multiple conditions in WHERE clause
我在下面的 SQL 字符串上遇到 运行 时间 3075 问题。有没有可能我漏了括号?
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
检查您的代码创建的语句的 WHERE
子句。
这是一个即时 window 会话:
sql_get = "WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>"""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>" or [tblcompetency04].[team]<>" or [tblcompetency04].[organisation]<>"
请注意,在每种情况下只有一个双引号字符:<>"
如果你想在字符串中有双引号,用两个得到一个...
sql_get = "WHERE [tblcompetency04].[self]<>"""" or [tblcompetency04].[team]<>"""" or [tblcompetency04].[organisation]<>"""""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>""
但我认为在字符串中使用单引号更容易混淆,也更不容易出错 ...
sql_get = "WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''"
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''
我在下面的 SQL 字符串上遇到 运行 时间 3075 问题。有没有可能我漏了括号?
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
检查您的代码创建的语句的 WHERE
子句。
这是一个即时 window 会话:
sql_get = "WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>"""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>" or [tblcompetency04].[team]<>" or [tblcompetency04].[organisation]<>"
请注意,在每种情况下只有一个双引号字符:<>"
如果你想在字符串中有双引号,用两个得到一个...
sql_get = "WHERE [tblcompetency04].[self]<>"""" or [tblcompetency04].[team]<>"""" or [tblcompetency04].[organisation]<>"""""
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>"" or [tblcompetency04].[team]<>"" or [tblcompetency04].[organisation]<>""
但我认为在字符串中使用单引号更容易混淆,也更不容易出错 ...
sql_get = "WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''"
Debug.Print sql_get
WHERE [tblcompetency04].[self]<>'' or [tblcompetency04].[team]<>'' or [tblcompetency04].[organisation]<>''