Dim dr1,dr2,dr3 As DataRow
Dim dtb As New DataTableBuilder("统计表2")
dtb.AddDef("姓名", Gettype(String), 32)
dtb.AddDef("部门", Gettype(String), 32)
dtb.AddDef("级别", Gettype(String), 32)
For Each v As String In DataTables("表A").GetUniqueValues("","期间")
dtb.AddDef("成本中心_" & v, Gettype(String))
Next
For Each v As String In DataTables("表A").GetUniqueValues("","期间")
dtb.AddDef("基本工资_" & v, Gettype(String))
Next
dtb.Build()
For Each v As String In DataTables("表A").GetUniqueValues("","姓名")
dr1 = DataTables("统计表2").AddNew()
dr1("姓名") = v
For Each dr2 In DataTables("表A").DataRows
If dr2("姓名") = v Then
dr1("成本中心_" & dr2("期间")) = dr2("成本中心")
End If
Next
For Each dr3 In DataTables("表A").DataRows
If dr3("姓名") = v Then
dr1("基本工资_" & dr3("期间")) = dr3("基本工资")
End If
Next
Next
For Each dr1 In DataTables("统计表2").DataRows
dr2 = DataTables("表B").Find("姓名 = '" & dr1("姓名") & "'")
If dr2 IsNot Nothing Then
dr1("部门") = dr2("部门")
dr1("级别") = dr2("级别")
End If
Next
MainTable = Tables("统计表2")