How to connect to a Teradata database on a remote server

Szurya

New Member
Joined
Jul 18, 2012
Messages
2
Hello friends,

I need help in connecting to a Teradata database on a remote server. I could comeup with a VBA for connecting to 'Teradata' database locally with in that server and want to move my solution a step further where the user would be able to connect to the database in a server and get the result into the Excel sheet in their local system.

This is what I'm doing now
1. Connect to the server via 'mstdc' in windows, enter User ID and Password Manually.
2. Once connected, open an excel sheet and run this below VBA script, which connects to the Teradata database and runs a query(built in the VB script) and provide the result.

My VB Script:

Code:
Sub CommandButton1_Click()


CreateObject ("ADODB.Connection")
Dim conn As ADODB.Connection
Dim rec1 As ADODB.Recordset
Dim thisSql As String


Set conn = New ADODB.Connection


conn.Open ("DRIVER={Teradata};DBCNAME=xxx.xx.xx.xx;UID=xxxx;PWD=xxyy;QUIETMODE=YES;")


thisSql = ""
thisSql = thisSql & " SELECT         calendar_date, a.Section_Number,a.class_number,a.subclass_number, "
thisSql = thisSql & " cast(SUM(Sales_Value) as decimal(18,4)) sales_value, "
Set rec1 = New ADODB.Recordset
rec1.Open thisSql, conn


With Sheet1.QueryTables.Add(Connection:=rec1, Destination:=Sheet1.Range("A1"))
    .Name = "data"
    .FieldNames = True
   .Refresh BackgroundQuery:=False
End With


End Sub


Thanks
Surya
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top