以下のコードは、Yahoo Developers の記事からコピーし、それに応じて変更したものです。Query の場合、Excel から Teradata に 2999 行の挿入ステートメントをコピーして貼り付けたいと考えています。私の現在の方法では、範囲全体をコピーして貼り付けることはできません。これを交換すると: Cells(1, 1) & " " & Cells(2, 1) & " " & Cells(3, 1)....etc. Cells(2999) までは動作します。これを行う賢い、より簡単な方法を教えてください。
余談ですが、2999行を挿入する別の方法をお勧めしますか? テーブルには既に値が設定されているため、FLOAD は機能しません。MLOADまたはBTEQ? 2999 は十分に小さいため、通常の挿入ステートメントを使用しています。しかし、私はいつもより迅速な解決策に非常に感謝しています! 皆さん、ありがとうございました!
Sub Insert_to_TD()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cmdsqldata As ADODB.Command
Set cmdsqldata = New ADODB.Command
cn.Open "DSN=NNNNNN; Username=XXXXX; Password=YYYYYYY;"
Set cmdsqldata.ActiveConnection = cn 'This line says to which database it has to send the query
Query = Range(Cells(1, 1), Cells(2999, 1))
cmdsqldata.CommandText = Query 'We asign the query as command text
cmdsqldata.CommandType = adCmdText 'We just say what kind of command VBA has to execute
cmdsqldata.CommandTimeout = 0 'With this instruction we don't set any timeout, so the query can take all the necessary time to be executed
Set rs = cmdsqldata.Execute() 'VBA just run the query and send back the result
End Sub