Hi everyone. If this question exists in the forum I apologize, but I've searched and could not find anything.
What I have is a module which queries Teradata, and the SQL statement passes a variable "x" in the where statement. "x" is tied to Sheet1.A1, works fine, returns the correct result on the single value. What I need to do and have been trying to do is pass "x" as multiple values that would be in a1:a10 (cust_name), this I cannot get to work. For now I'm just dumping the results into Sheet3 during this testing process.
Sub edw_connection()
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 x
x = Sheet1.Range("a1").Text
cn.Open "Data Source=EDW; Database=prod_view; Persist Security Info=True; User ID=xxxxx; Password=xxxxx; Session Mode=ANSI;"
Set cmdSQLData.ActiveConnection = cn
Query = "SELECT item FROM detail where cust_name in ('" & x & "');"
cmdSQLData.CommandText = Query
cmdSQLData.CommandType = adCmdText
cmdSQLData.CommandTimeout = 0
Set rs = cmdSQLData.Execute()
Sheet3.Range("a:a").Delete
With Sheet3.QueryTables.Add(Connection:=rs, Destination:=Sheet3.Range("A1"))
.Name = "data"
.FieldNames = True
.Refresh BackgroundQuery:=False
End With
cn.Close
Set cn = Nothing
Set rs = Nothing
Set cmdSQLData = Nothing
End Sub
How do I make x pass multiple values to the query, or is it even possible?
Appreciate any help anyone can provide. Thanks.
Bookmarks