您好我正在开发一个MVC4应用程序。我正在研究一个复杂的查询,实际上我不知道这是否可行。我将解释这个场景,我会把我到目前为止尝试的内容。 我在SQL中有一个日志日志表,结构如下。
Option Explicit
Sub remDup()
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")
Dim ws3 As Worksheet: Set ws3 = ThisWorkbook.Sheets("Sheet3")
Dim LR As Long, LRSheet2 As Long, i As Long, a As Long
Dim vAllSheet2Values() As String, sheet2Val As Variant
LRSheet2 = ws2.Cells(ws2.Rows.Count, 3).End(xlUp).Row
LR = ws1.Cells(ws1.Rows.Count, 11).End(xlUp).Row
a = 2
For i = 1 To LRSheet2
ReDim Preserve vAllSheet2Values(i)
If ws2.Cells(i, 3).Value <> "" Then _
vAllSheet2Values(i) = CStr(ws2.Cells(i, 3).Value) 'Don't add blanks
Debug.Print ws2.Cells(i, 3).Value
Next i
For i = LR To 1 Step -1
If ws1.Cells(i, 11).Value = "" Then GoTo SkipTheRest 'Skip blanks
For Each sheet2Val In vAllSheet2Values
If InStr(sheet2Val, CStr(ws1.Cells(i, 11).Value)) <> 0 Then
ws1.Rows(i).Copy ws3.Rows(a)
ws1.Rows(i).Delete
a = a + 1
GoTo SkipTheRest 'Match found, skip the rest
End If
Next sheet2Val
'You can include the following statement if you want to catch when there
'isn't a match on Sheet1
'MsgBox "No match found for " & ws1.Cells(i, 11).Value, vbOKOnly, "No Match"
SkipTheRest:
Next i
End Sub
这是我的日志表。例如,护照将包含字段Docnumber和expirydate。最初上传时,不会进行验证。后来的管理员拒绝它并批准它。每个操作我都在维护updateVersion。现在我想要结果如下。
ID uploadID docType updateVersion FieldName FieldValue Status
1 1 Passport 1 Docnumber 123 NotVerified
2 1 Passport 1 Expirydate 01/01/2016 NotVerified
3 1 Passport 2 Docnumber 456 Rejected
4 1 Passport 2 Expirydate 01/01/2017 Rejected
5 1 Passport 3 Docnumber 789 Approved
6 1 Passport 3 Expirydate 01/01/2019 Approved
在结果表格中,我期待旧值,新值,旧状态和新状态。我通过updateVersion跟踪每个条目。但是我想显示特定的upldId初始值和最后更新的值。我想跳过中间值。有人能告诉我这可以在LINQ中实现或者我是否需要使用任何其他逻辑?谢谢你们。