如何在SQL查询中例外(访问Excel)

时间:2019-04-19 14:42:01

标签: sql excel vba access-vba

我正在从Access表中获取一些数据到Excel工作表,它们取决于一些参数。我在访问表上的数据列表包括例如:

1-x branch
2-y branch
3-z branch
4-t commercial branch
5-r commercial branch
6-w corporate branch
7-g corporate branch

在Excel VBA上,如果我想检索所有数据,我正在创建一个SQL查询,如下所示:

sql = "select * from [table] where [Branches] like "%"

如果我只想检索商业分支机构数据:

sql = "select * from [table] where [Branches] like '%" & "commercial" & "%'"

如果我只想检索公司分支机构数据:

sql = "select * from [table] where [Branches] like '%" & "corporate" & "%'"

这是问题。如果要检索公司和商业分支机构以外的数据,该怎么办?我们可以创建哪种类型的SQL查询?

非常感谢。


这很糟糕,我可以解释得更清楚。在创建查询之前,我正在使用如下参数:

Select Case main.Range("D6").Value
Case "ALL"
brnch = "%"
Case "CORPORATE"
brnch = "%" & "CORPORATE" & "%"
Case "COMMERCIAL"
brnch = "%" & "COMMERCIAL" & "%"
End Select

我的查询实际上就是这样:

sql = "select * from [table] where [Branches] like '" & brnch & "'"

现在我该怎么办才能检索没有广告和公司的分支机构。

1 个答案:

答案 0 :(得分:2)

您可以使用let amount = 6; let highest = amount - 1,second_highest = amount - 2,third_highest = amount - 3; let possibilities = [ highest + highest, highest + second_highest, highest + third_highest ]; console.log(possibilities);

CMD [ "run.sh" ]

如果要在MS Access中运行此代码,则通配符不同,并且字符串定界符为双引号:

not like