以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  状态更新  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=108211)

--  作者:huhuyq
--  发布时间:2017/10/18 15:02:00
--  状态更新
请问什么方法效率更高一点来更新版本状态,数据有几万行,遍历一遍需要很长时间
Rev REV_Status Document_No RecieveDate
B New P055AZOR-01FL00-3092-01 2017/10/2 0:00
A New P055AZOR-01FO00-1164-01 2017/10/2 0:00
O Updated P055AZOR-01FO00-1492-20 2017/10/2 0:00
A New P055AZOR-01FO00-1563-01 2017/10/2 0:00
A New P055AZOR-01FO00-1915-01 2017/10/2 0:00
A New P055AZOR-01FO00-1942-01 2017/10/2 0:00

For Each u As String In DataTables("ISO_Index").SQLGetValues("Document_No")
    If DataTables("ISO_Index").SQLCompute("Count([_Identify])","Document_No = \'" & u & "\'") > 1 Then
        Dim md As Date = DataTables("ISO_Index").SQLCompute("Max(RecieveDate)","Document_No = \'" & u & "\'")
        Dim dss As List(Of DataRow)
        dss = DataTables("ISO_Index").SQLSelect("[Document_No] = \'" & u & "\'")
        For i As Integer = 0 To dss.Count-1
            If dss(i)("RecieveDate") < md Then
                dss(i)("REV_Status") = "Updated"
            Else
                dss(i)("REV_Status")  = "New"
            End If
        Next
    End If
Next


--  作者:有点甜
--  发布时间:2017/10/18 15:40:00
--  

方法一:

 

DataTables("ISO_Index").loadfilter = ""
DataTables("ISO_Index").loadTop = "100 percent"
DataTables("ISO_Index").load
msgbox(2)
For Each u As String In DataTables("ISO_Index").GetValues("Document_No")
    If DataTables("ISO_Index").Compute("Count([_Identify])","Document_No = \'" & u & "\'") > 1 Then
        Dim md As Date = DataTables("ISO_Index").Compute("Max(RecieveDate)","Document_No = \'" & u & "\'")
        Dim dss As List(Of DataRow)
        dss = DataTables("ISO_Index").Select("[Document_No] = \'" & u & "\'")
        For i As Integer = 0 To dss.Count-1
            If dss(i)("RecieveDate") < md Then
                dss(i)("REV_Status") = "Updated"
            Else
                dss(i)("REV_Status")  = "New"
            End If
        Next
    End If
Next


--  作者:有点甜
--  发布时间:2017/10/18 15:44:00
--  

方法二:

 

可以先生成分组统计表,得到每个 No 对应的最大值,然后用 SQLReplaceFor 直接更新 http://www.foxtable.com/webhelp/scr/2898.htm

 


--  作者:有点甜
--  发布时间:2017/10/18 15:44:00
--  

方法三:上传具体实例测试。


--  作者:huhuyq
--  发布时间:2017/10/18 16:25:00
--  


请查阅

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目6.rar


--  作者:有点甜
--  发布时间:2017/10/18 20:12:00
--  

2楼,或者下面代码


Dim dt As DataTable = DataTables("ISO_Index")
dt.loadfilter = ""
dt.loadTop = "100 percent"
dt.load(False)

Dim pdr As DataRow = Nothing
For Each dr As DataRow In dt.Select("", "Document_No, RecieveDate desc")
    If pdr Is Nothing OrElse pdr("Document_No") <> dr("Document_No") Then
        dr("REV_Status")  = "New"
        pdr = dr
    Else
        If dr("RecieveDate")<pdr("RecieveDate") Then
            dr("REV_Status") = "Updated"
        Else
            dr("REV_Status") = "new"
        End If
    End If
Next


--  作者:huhuyq
--  发布时间:2017/10/19 16:13:00
--  
谢谢,老师了