简体   繁体   English

MS Access VBA,SQL脚本:In(),<>和AND语法

[英]MS Access VBA, SQL Script: In(), <>, AND syntaxes

I have a script I need to show the genres and filter out nulls. 我有一个脚本,需要显示类型并过滤出空值。

ReturnBooks = "Select * from [Books] where ([Type] IN ('B','K' ,'R' ,'C') AND [Type] <> 'No' AND [BookGenre] IS NOT NULL)) Order By [LName] ASC"

I need the BookGenre to be not null but the syntax returns nothing. 我需要BookGenre不为null,但语法不返回任何内容。 Originally the code did not have that line and it did return some results. 最初,代码没有该行,并且确实返回了一些结果。

ReturnBooks = "Select * from [Books] where ([Type] IN ('B','K' ,'R' ,'C') AND [Type] <> 'No') Order By [LName] ASC"

Which returns the type of book. 返回书的类型。

How might I fit the IS NOT NULL in the script? 如何将IS NOT NULL放入脚本中?

For example books table would return an author by last name depending on the genre. 例如,books表将根据类型返回姓氏的作者。 I also get a datatype mismatch from the script. 我还从脚本中获得了数据类型不匹配的信息。

You have disbalance of parentheses in your query. 您的查询中括号不平衡。

And you need to show some sample data from you table in your database. 并且您需要从数据库表中显示一些示例数据。

Let's check you where clause: ([Type] IN ('B','K' ,'R' ,'C') AND [Type] <> 'No') AND [BookGenre] IS NOT NULL)) 让我们检查一下where子句: ([Type] IN('B','K','R','C')AND [Type] <>'No') AND [BookGenre]不为空))

If your [Type] in ('B','K' ,'R' ,'C') then it would never be 'No', so, the "And Type <> 'No'" is no use. 如果您的[Type]在('B','K','R','C')中,则它永远不会是'No',因此,“ And Type <>'No'”是没有用的。

"IS NOT NULL" phare works well with mysql, sqlserver. “ IS NOT NULL”阶段与mysql,sqlserver一起使用时效果很好。

If you only just need the records that BookGenre is not null, just use this: 如果仅需要BookGenre不为null的记录,则使用此命令:

ReturnBooks = "SELECT * FROM [Books] WHERE [BookGenre] IS NOT NULL ORDER BY [LName] ASC"

If you need to filter the record with BookGenre is blank as well, try this: 如果您也需要使用BookGenre将记录过滤为空白,请尝试以下操作:

ReturnBooks = "SELECT * FROM [Books] WHERE ([BookGenre] IS NOT NULL) AND ([BookGenre] <> '')  ORDER BY [LName] ASC"

Hoped this may help you. 希望这对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM