Note that there are some explanatory texts on larger screens.

plurals
  1. POfind duplicate insert into another table
    text
    copied!<p>I have a code that that loads my data into sql table. I want know that is there any way to load data into some other table if there is any duplicate value. if yes can you help me. My query is: </p> <blockquote> <p>"insert into t_DATA_DneFrc (RTN, AccountNbr, FirstName, MiddleName, LastName, Amount) values ('" &amp; rcdDNE("RTN") &amp; "', '" &amp; rcdDNE("AccountNbr") &amp; "', '" &amp; rcdDNE("FirstName") &amp; "', '" &amp; rcdDNE("MiddleName") &amp; "', '" &amp; rcdDNE("LastName") &amp; "', '" &amp; rcdDNE("Amount") &amp; "')"</p> </blockquote> <p>that will insert data into <code>t_DATA_DneFrc</code> table. Now i want change the query if there is duplicate insert that row into <code>t_DATA_DneFrcDuplicate</code>. Is that possible?</p> <pre><code> ' Write records to Database frmDNELoad.lblStatus.Caption = "Loading data into database......" Dim lngRecCount As Long lngRecCount = 0 rcdDNE.MoveFirst With cmdCommand .ActiveConnection = objConn .CommandText = "insert into t_DATA_DneFrc (RTN, AccountNbr, FirstName, MiddleName, LastName, Amount) values ('" &amp; rcdDNE("RTN") &amp; "', '" &amp; rcdDNE("AccountNbr") &amp; "', '" &amp; rcdDNE("FirstName") &amp; "', '" &amp; rcdDNE("MiddleName") &amp; "', '" &amp; rcdDNE("LastName") &amp; "', '" &amp; rcdDNE("Amount") &amp; "')" .CommandType = adCmdText End With Set rcddnefrc = New ADODB.Recordset With rcddnefrc .ActiveConnection = objConn .Source = "SELECT * FROM T_DATA_DNEFRC" .CursorType = adOpenDynamic .CursorLocation = adUseClient .LockType = adLockOptimistic .Open End With Do Until rcdDNE.EOF lngRecCount = lngRecCount + 1 frmDNELoad.lblStatus.Caption = "Adding record " &amp; lngRecCount &amp; " of " &amp; rcdDNE.RecordCount &amp; " to database." frmDNELoad.Refresh DoEvents Call CommitNew rcdDNE.MoveNext Loop frmDNELoad.lblStatus.Caption = "DNE Processing Complete." frmDNELoad.Refresh End Function Sub CommitNew() ' Add records to DneFrc table With rcddnefrc .Requery .AddNew .Fields![RTN] = rcdDNE.Fields![RTN] .Fields![AccountNbr] = rcdDNE.Fields![AccountNbr] .Fields![FirstName] = rcdDNE.Fields![FirstName] .Fields![MiddleName] = rcdDNE.Fields![MiddleName] .Fields![LastName] = rcdDNE.Fields![LastName] .Fields![Amount] = rcdDNE.Fields![Amount] .Update End With </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload