是否有一种方法可以在查询中将空值与选定的值一起包括?

huangapple go评论61阅读模式
英文:

Is there a way to include null values along with selected values in query

问题

当筛选多个类别时,我试图向当前的连接字符串添加一个新的筛选器,以更新已选择的内容,同时也包括空值到 SQL 语句中。我尝试过 (query += query & color = selected OR query & color Is Null,但最终只获取非空值。

这是我尝试过的一个示例:

If Nz(colorFilter, "-") <> "All" Then
    query = query & " AND Color Is Null OR Color=" & Chr(34) & Me.colorFilter & Chr(34) & query
End If

请注意,代码中的 """ 和 "&" 是 HTML 实体,用于表示双引号和与号,需要根据实际情况进行替换。

英文:

When filtering multiple categories, I am attempting to add a new filter to a current concatenated string that updates what has been selected, but also includes null values to an sql statement. I have tried (query += query & color = selected OR query & color Is Null, but it ends up only grabbing the non null values.

Here is an example of something I've tried

If Nz(colorFilter, "-") <> "All" Then
    query = query & " AND Color Is Null OR Color=" & Chr(34) & Me.colorFilter & Chr(34) & query
End If

答案1

得分: 1

query = query & " AND (Color Is Null OR Color = " & Chr(34) & Me.colorFilter & Chr(34) & ")"

英文:

Try this:

query = query & " AND (Color Is Null OR Color = " & Chr(34) & Me.colorFilter & Chr(34) & ")"

huangapple
  • 本文由 发表于 2023年2月7日 04:24:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定