現時点では、「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
私の質問は、私の構文の何が問題なのですか?