Ciao a tutti.
Vi spiego il problema:
1) la fonte dati di partenza è una tabella access, la fonte dati di arrivo è MySQL;
2) devo importare dalla tabella A dei records in tabella B;
3) le due tabelle sono perfettamente uguali con gli stessi campi: ID, matr, nome, aut;
4) durante l'importazione controllo se i records non siano già presenti;
5) se non sono presenti i records li inserisco in tabella B
Il problema è che potrei avere dei records sia in tabella A che in tabella B differenti soltanto per il valore del campo comune aut che può essere vuoto o valorizzato.
Se la query di controllo esistenza record la eseguo controllando tutti i campi della tabella B se aut è vuoto la query mi va in errore.
Cosa sbaglio?
Questo è il codice:
codice:SQL = " SELECT * FROM tbl_access " Set objRs = CreateObject("ADODB.Recordset") objRs.Open SQL, conn, 3, 3 if not objRs.eof then objRS.movefirst() do while not objRS.eof query_select = "SELECT * FROM " query_select = query_select & " tbl_A " query_select = query_select & " WHERE " query_select = query_select & " Matr = '" & objRs("Matr") & "' " query_select = query_select & " AND " query_select = query_select & " Nome = '" & pulisci(replace(objRs("Nome"), ",", ".")) & "' " set RS = CreateObject("ADODB.Recordset") Rs.Open query_select, cn if Rs.eof And Rs.bof then strSQL = " INSERT INTO " strSQL = strSQL & " tbl_B " strSQL = strSQL & " ( " strSQL = strSQL & " Matr, " strSQL = strSQL & " Nome, " strSQL = strSQL & " Aut " strSQL = strSQL & " ) " strSQL = strSQL & " VALUES " strSQL = strSQL & " ( " strSQL = strSQL & " '" & objRs("Matr") & "', " strSQL = strSQL & " '" & pulisci(replace(objRs("Nome"), ",", ".")) & "', " strSQL = strSQL & " '" & objRs("aut") & "' " strSQL = strSQL & " ) " cn.execute (strSQL) end if objRS.movenext() Loop end if

Rispondi quotando
