目前我收到错误“Build WHERE -> insert_fields()”。此代码发生此错误:
Do Until rCurrent.EOF
rCurrent.MoveNext
Loop
rCurrent 是一个 ADODBRecordSet,它被赋予了以下值:
sSQL = ""
sSQL = sSQL & "SELECT v_final_transactions.* " & vbCrLf
sSQL = sSQL & "FROM v_final_transactions " & vbCrLf
sSQL = sSQL & "WHERE ( " & vbCrLf
sSQL = sSQL & " ( " & vbCrLf
sSQL = sSQL & "( v_final_transactions.contact_id ) = " & rcampaigninclusion!contact_id & " ) " & vbCrLf
sSQL = sSQL & "AND " & vbCrLf
sSQL = sSQL & "( " & vbCrLf
sSQL = sSQL & "( v_final_transactions.dbd_segment ) = '" & rCampaignInclusion!PRODUCT_SEGMENT_1 & "' ) ) " & vbCrLf
sSQL = sSQL & " OR ( " & vbCrLf
sSQL = sSQL & "( ( v_final_transactions.contact_id ) = " & rcampaigninclusion!contact_id & " ) " & vbCrLf
sSQL = sSQL & "AND " & vbCrLf
sSQL = sSQL & "( " & vbCrLf
sSQL = sSQL & "( v_final_transactions.dbd_segment ) = '" & rCampaignInclusion!PRODUCT_SEGMENT_2 & "' ) ) " & vbCrLf
sSQL = sSQL & " OR " & vbCrLf
sSQL = sSQL & "(( ( v_final_transactions.contact_id ) = " & rcampaigninclusion!contact_id & " ))"
Set rCurrent = New ADODB.Recordset
rCurrent.Open sSQL, cDS, adOpenStatic, adLockOptimistic, adCmdText
最终的 SQL 如下所示:
SELECT V_FINAL_TRANSACTIONS.*
FROM V_FINAL_TRANSACTIONS
WHERE (
(
( V_FINAL_TRANSACTIONS.CONTACT_ID ) = 1036219 )
AND
(
( V_FINAL_TRANSACTIONS.DBD_SEGMENT ) ='Acrobat' ) )
OR (
( ( V_FINAL_TRANSACTIONS.CONTACT_ID ) = 1036219 )
AND
(
( V_FINAL_TRANSACTIONS.DBD_SEGMENT ) = '' ) )
OR
(( ( V_FINAL_TRANSACTIONS.CONTACT_ID ) = 1036219 ))
这是运行的逻辑:
If rCurrent.Properties.Count > 0 Then
If (rCurrent.EOF = False) Then
rCurrent.MoveFirst
End If
Do Until rCurrent.EOF
dTransDate = rCurrent!TRANSACTION_DATE
If (rCampaignInclusion!CAMPAIGN_ID = 446) And (dTransDate >= rCampaignInclusion!DATE_UPDATE) And (dTransDate <= (rCampaignInclusion!DATE_UPDATE + 90)) Then
iDifference = dTransDate - rCampaignInclusion!DATE_UPDATE
iCampaignHistory = rCampaignInclusion!CAMPAIGN_HISTORY_ID
If rCurrent!REVENUE > 0 Then
iTransactionRevenue = rCurrent!REVENUE
Else
iTransactionRevenue = 0
End If
sSQLMatched = "INSERT INTO TMP_MATCH_CON_HISTORY_UPDATE ( TRANSACTION_08_ID, CAMPAIGN_HISTORY_ID, DATE_UPDATE, RESULT_VALUE_2, NO_DAYS) SELECT " & rCurrent!TRANSACTION_08_ID & ", " & iCampaignHistory & ", '" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & "', " & iTransactionRevenue & ", " & iDifference & ";"
cDS.Execute (sSQLMatched)
'rCurrent.Edit
'rCurrent!MATCHED = "Y"
'rCurrent.Update
sSQLMatched = "UPDATE TMP_MATCH_TRANSACTIONS SET MATCHED='Y' WHERE TMP_MATCH_TRANSACTIONS.TRANSACTION_08_ID=" & rCurrent!TRANSACTION_08_ID
cDS.Execute (sSQLMatched)
ElseIf (dTransDate >= rCampaignInclusion!CAMPAIGN_DATE_START) And (dTransDate <= rCampaignInclusion!CAMPAIGN_DATE_END) Then
iDifference = dTransDate - rCampaignInclusion!CAMPAIGN_DATE_START
iCampaignHistory = rCampaignInclusion!CAMPAIGN_HISTORY_ID
If rCurrent!REVENUE > 0 Then
iTransactionRevenue = rCurrent!REVENUE
Else
iTransactionRevenue = 0
End If
sSQLMatched = "INSERT INTO TMP_MATCH_CON_HISTORY_UPDATE ( TRANSACTION_08_ID, CAMPAIGN_HISTORY_ID, DATE_UPDATE, RESULT_VALUE_2, NO_DAYS) SELECT " & rCurrent!TRANSACTION_08_ID & ", " & iCampaignHistory & ", '" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & "', " & iTransactionRevenue & ", " & iDifference & ";"
cDS.Execute (sSQLMatched)
'rCurrent!MATCHED = "Y"
'rCurrent.Update
sSQLMatched = "UPDATE TMP_MATCH_TRANSACTIONS SET MATCHED='Y' WHERE TMP_MATCH_TRANSACTIONS.TRANSACTION_08_ID=" & rCurrent!TRANSACTION_08_ID
cDS.Execute (sSQLMatched)
End If
rCurrent.MoveNext
Loop
所以我的问题是我的语法有什么问题?