Foxtable(狐表)用户栏目专家坐堂 → 获取不重复的对象属性后,怎么根据对象属性值去对应的遍历表中是否有符合条件的列,如果有就对应的计算值


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

主题:获取不重复的对象属性后,怎么根据对象属性值去对应的遍历表中是否有符合条件的列,如果有就对应的计算值

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


加好友 发短信
等级:超级版主 帖子:109760 积分:558516 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/8/6 11:05:00 [显示全部帖子]

表数据是怎么样的?希望得到什么结果?

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


加好友 发短信
等级:超级版主 帖子:109760 积分:558516 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/8/6 11:51:00 [显示全部帖子]

请上传实例测试

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


加好友 发短信
等级:超级版主 帖子:109760 积分:558516 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/8/6 13:47:00 [显示全部帖子]

试试

Dim cmd As New SQLCommand
cmd.Connecti
cmd.CommandText = "Select distinct 巡察对象属性 From {巡察工作安排}"
Dim dt As DataTable
dt = cmd.ExecuteReader()
Dim Products As List(Of String)
Products = dt.GetValues("巡察对象属性")
Dim time As String = Date.today.Year
Dim y As Integer = time '指定年份
Dim time1 As New Date(y, 1, 1)
Dim time2 As New Date(y, 12, 31)

cmd.CommandText = "Select * From {巡察工作覆盖情况} where [_identify] = -1"
Dim dt1 As DataTable
dt1 = cmd.ExecuteReader(True)
Dim bb As DataRow = dt1.AddNew


Dim yxs As Integer
Dim yxs1 As Integer
Dim bnd As Integer
For Each Product As String In Products
    Dim cl As String = Product & "_应巡数"
    Output.Show(cl)
    If dt1.DataCols.Contains(cl) Then
        cmd.CommandText = "Select Count(*) From {巡察对象信息} Where 巡察对象属性 = '" & Product & "'"
        Dim sl2 As Integer = cmd.ExecuteScalar
        If sl2 > 0 Then
            bb(cl) = sl2
            yxs = yxs + sl2
        End If
    End If
    cl = Product & "_已巡数"
    If dt1.DataCols.Contains(cl) Then
        cmd.CommandText = "Select Count(*) From {巡察工作安排} Where 巡察对象属性 = '" & Product & "'"
        Dim sl2 As Integer = cmd.ExecuteScalar
        If sl2 > 0 Then
            bb(cl) = sl2
            yxs1 = yxs1 + sl2
        End If
    End If
    cl = Product & "_本年度"
    If dt1.DataCols.Contains(cl) Then
        cmd.CommandText = "Select Count(*) From {巡察工作安排} Where 巡察对象属性 = '" & Product & "' and 巡察开始时间 >= '" & time1 & "' And 巡察开始时间 <= '" & time2 & "'"
        Dim sl2 As Integer = cmd.ExecuteScalar
        If sl2 > 0 Then
            bb(cl) = sl2
            bnd = bnd + sl2
        End If
    End If
Next
output.show(yxs)
bb("总计_应巡数") = yxs
bb("总计_已巡数") = yxs1
bb("总计_覆盖率") = bnd
bb.save


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


加好友 发短信
等级:超级版主 帖子:109760 积分:558516 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/8/13 8:34:00 [显示全部帖子]

数据统计的结果肯定没有问题,如果有问题也是条件不对,或者数据有问题

 回到顶部