繁体   English   中英

使用VBA上传挥发表

[英]Uploading Volatile Table using VBA

我在MS Access 2010数据库中有一个本地表。 我想使用ADODB通过CREATE VOLATILE TABLE命令将本地表加载到后台打印空间内的Teradata环境中

我认为使用数组应该可以实现,但是我想知道是否有更好的方法(如果可能的话也可以快速)将记录批量加载到Teradata环境中。

CREATE VOLATILE TABLE EXAMPLE AS (SELECT * FROM LOCAL TABLE)
WITH DATA PRIMARY INDEX(Set Index Keys)
ON COMMIT PRESERVE ROWS;

谢谢你的帮助

请对此快速更新[24/01/2013]

我已经设法从访问数据库中获取数据,将其加载到阵列中,使用后台处理空间在我的Teradata仓库中创建一个Volatile表,然后尝试将阵列加载到表中

我收到错误消息:TEMP_TABLE已经存在。 尝试将记录追加到表时

我快到了,因此任何帮助将不胜感激。 再次感谢你的帮助

Public Function Open_Connection()

On Error GoTo ErrorHandler

    ' http://voices.yahoo.com/teradata-ms-excel-vba-2687156.html
    ' The connection is used to connect with the DBMS,
    ' The Recordset to surf the result of some SELECT queries
    ' The Command to send the sql requests to Teradata.

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
Dim myArray() As Variant

' Open Connection With Teradata
cn.Open "Data Source=Database; " & _
        "Database=Database; " & _
        "Persist Security Info=True; " & _
        "User ID=Me; " & _
        "Password=FakePassword; " & _
        "Session Mode=ANSI;"

' Which database it has to send the query
Set cmdSQLData.ActiveConnection = cn

   ' Query to create the violotile table in Teradata'
       Query = "CREATE VOLATILE TABLE TEMP_TABLE ( " & _
            "field1 VARCHAR (39)," & _
            "field2 VARCHAR (44)," & _
            "field3 DECIMAL (18, 3)," & _
            "field4 CHAR (3))" & _
            "ON COMMIT PRESERVE ROWS;"

' Query is assessed as Text
cmdSQLData.CommandText = Query
' Specifies which kind of command VBA has to execute
cmdSQLData.CommandType = adCmdText
' Remove Query Timeouts
cmdSQLData.CommandTimeout = 60
'VBA just run the query and send back the result
Set rs = cmdSQLData.Execute()

' Retrieve the sharepoint records into an Array
myArray = Retrieve_Sharepoint_Records

intNumberRows = UBound(myArray, 2) + 1 ' number of records/rows in the array
rowcounter = 0

' Append the Rows to the temp table
For rowcounter = 0 To intNumberRows - 1
        ' Debug.Print myArray(0, rowcounter) & " | " & myArray(1, rowcounter) & " | " & myArray(2, rowcounter) & " | " & myArray(3, rowcounter)
    AppendQuery = "INSERT INTO TEMP_TABLE VALUES ('" & myArray(0, rowcounter) & "','" & myArray(1, rowcounter) & "'," & myArray(2, rowcounter) & ",'" & myArray(3, rowcounter) & "');"

    cmdSQLData.CommandText = Query
    cmdSQLData.CommandType = adCmdText
    cmdSQLData.CommandTimeout = 60
    Set rs = cmdSQLData.Execute()

Next

' Clean up
cn.Close
Set cn = Nothing
Set rs = Nothing
Set cmdSQLData = Nothing

ErrorHandler:
If (Len(Err.Description) > 0) Then
    MsgBox (Err.Description)
End If

End Function

使用Global Temporary Table可能会获得更好的成功,因为对象定义存储在Teradata上的DBC数据字典中。 该表的填充是特定于会话的,使用分配给用户的TEMPORARY空间或用户的个人资料。

只是为了回答我自己的问题,我应该更改下面的第二行代码

cmdSQLData.CommandText = Query

cmdSQLData.CommandText = AppendQuery

即使缓慢,它也可以正常工作

再次感谢大家的帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM