0
這與MS Access數據庫有關。SQL變量 - MS Access
我知道有可能在T-SQL中定義變量,但是這將在MS Access中工作以及如何實現?
如何在SQL中爲變量賦值,方法與下面的VBA腳本相同? 正如你所看到的,目的是爲用戶提供的什麼地方出了錯使用說明:
strErrorDescription = strErrorDescription & " " & strErrorDescription2 & " " & strErrorDescription3
strTableName = "tblStagingGL_SS04"
strLogTableName = "tblLogGL_SS04"
Set rs = db.OpenRecordset(strTableName)
Set rs2 = db.OpenRecordset(strLogTableName)
rs.MoveFirst
Do Until rs.EOF
'Verifies that the GL_Number only contains numbers
If rs.Fields(2).Value Like "*[!0-9]*" Then
strErrorDescription = "Error on GL_Number"
End If
'Verifies that the Currency is made of 3 numbers only
If Not rs.Fields(6).Value Like "[A-Z][A-Z][A-Z]" Then
strErrorDescription2 = "Error on Currency"
End If
'Verifies that the Rate does not contain letters
If rs.Fields(10).Value Like "*[A-Z]*" Then
strErrorDescription3 = "Error on rate"
End If
strErrorDescription = strErrorDescription & " " & strErrorDescription2 & " " & strErrorDescription3
'If an Error has been caught, create a record with the associated information in the Log table
If strErrorDescription <> " " Then
rs2.AddNew
rs2.Fields(1).Value = rs.Fields(2).Value
rs2.Fields(2) = rs.Fields(7)
rs2.Fields(3) = strErrorDescription
rs2.Update
End If
strErrorDescription = ""
strErrorDescription2 = ""
strErrorDescription3 = ""
rs.MoveNext
Loop
不知道很多關於MS Access的知識,但是您應該爲此使用存儲過程。此外,請注意'如果不是rs.Fields(6).Value就像「[A-Z] [A-Z] [A-Z]」然後'只檢查大寫字母(取決於您的排序規則)。 – HoneyBadger
在MS Access中沒有存儲過程... – ProtoVB
@ProtoVB您可以在Access中進行傳遞查詢以執行存儲過程 –