Foxtable(狐表)用户栏目专家坐堂 → [求助]sql空值和null的问题


  共有2244人关注过本帖树形打印复制链接

主题:[求助]sql空值和null的问题

帅哥哟,离线,有人找我吗?
晨曦396
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:266 积分:2478 威望:0 精华:0 注册:2019/2/15 9:43:00
[求助]sql空值和null的问题  发帖心情 Post By:2019/5/27 16:34:00 [只看该作者]

 新增时其中一个字段没有填入值,sql中是null 不是空值,在执行筛选时,不能筛选出来,如果输入空格再清除空格就可以筛选,这个问题如何处理
Dim StartDate As Date
Dim EndDate As Date
StartDate =RibbonTabs("基础成本").Groups("查找").Items("开始日期").value
EndDate = RibbonTabs("基础成本").Groups("查找").Items("结束日期").value

Dim filter As String = "[inputdate] > = #" & StartDate & "# and [inputdate] < = #" & EndDate & "#"
Dim sts() As String = {"BCID","input","usercode","fullname"}
For Each st As String In sts
    Dim var As String = RibbonTabs("基础成本").Groups("查找").Items(st).text
    If var IsNot Nothing  Then
        var = var.Replace("*","[*]")
        filter =filter & " and " & st & " Like '*" & var & "*'" 
    End If
Next
Tables("Basecost").Filter = filter

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/27 17:21:00 [只看该作者]

Dim StartDate As Date
Dim EndDate As Date
StartDate =RibbonTabs("基础成本").Groups("查找").Items("开始日期").value
EndDate = RibbonTabs("基础成本").Groups("查找").Items("结束日期").value

Dim filter As String = "1=1"
If startDate <> Nothing Then
    filter &= " and [inputdate] >= #" & StartDate & "#"
End If
If EndDate <> Nothing Then
    filter &= " And [inputdate] <= #" & EndDate & "#"
End If

Dim sts() As String = {"BCID","input","usercode","fullname"}
For Each st As String In sts
    Dim var As String = RibbonTabs("基础成本").Groups("查找").Items(st).text
    If var IsNot Nothing  Then
        var = var.Replace("*","[*]")
        filter =filter & " and " & st & " Like '%" & var & "%'"
    End If
Next
Tables("Basecost").Filter = filter


 回到顶部
帅哥哟,离线,有人找我吗?
晨曦396
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:266 积分:2478 威望:0 精华:0 注册:2019/2/15 9:43:00
  发帖心情 Post By:2019/5/28 10:39:00 [只看该作者]

以下是引用有点甜在2019/5/27 17:21:00的发言:

Dim StartDate As Date
Dim EndDate As Date
StartDate =RibbonTabs("基础成本").Groups("查找").Items("开始日期").value
EndDate = RibbonTabs("基础成本").Groups("查找").Items("结束日期").value

Dim filter As String = "1=1"
If startDate <> Nothing Then
    filter &= " and [inputdate] >= #" & StartDate & "#"
End If
If EndDate <> Nothing Then
    filter &= " And [inputdate] <= #" & EndDate & "#"
End If

Dim sts() As String = {"BCID","input","usercode","fullname"}
For Each st As String In sts
    Dim var As String = RibbonTabs("基础成本").Groups("查找").Items(st).text
    If var IsNot Nothing  Then
        var = var.Replace("*","[*]")
        filter =filter & " and " & st & " Like '%" & var & "%'"
    End If
Next
Tables("Basecost").Filter = filter

这个是日期的,如果是下面的集合中的字段呢?比如
Dim sts() As String = {"BCID","input","usercode","fullname"} 这个位置的这些字段


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/28 10:49:00 [只看该作者]

1、msgbox(filter) 看弹出的条件是否正确。

 

2、试试

 

Dim StartDate As Date
Dim EndDate As Date
StartDate =RibbonTabs("基础成本").Groups("查找").Items("开始日期").value
EndDate = RibbonTabs("基础成本").Groups("查找").Items("结束日期").value

Dim filter As String = "1=1"
If startDate <> Nothing Then
    filter &= " and [inputdate] >= #" & StartDate & "#"
End If
If EndDate <> Nothing Then
    filter &= " And [inputdate] <= #" & EndDate & "#"
End If
Dim sts() As String = {"BCID","input","usercode","fullname"}
For Each st As String In sts
    Dim var As String = RibbonTabs("基础成本").Groups("查找").Items(st).text
    If var = Nothing  Then
        '不操作
    Else
        var = var.Replace("*","[*]")
        filter =filter & " and " & st & " Like '%" & var & "%'"
    End If
Next
Tables("Basecost").Filter = filter


 回到顶部
帅哥哟,离线,有人找我吗?
晨曦396
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:266 积分:2478 威望:0 精华:0 注册:2019/2/15 9:43:00
  发帖心情 Post By:2019/5/28 11:34:00 [只看该作者]

 可以了谢谢!

 回到顶部