[TABLE="width: 64"]
<tbody>[TR]
[TD]Hi All,[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]It' been a while since I have posted an SQL query with VBA on here Xenou and you have been a massive help to me always[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]My question is, how do you write a string where I can am doing multiple statements[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]I.e[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]So in essence, I am running 1 statement if you like and all of the statements get run one after another[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Now how can I put the above into a an SqlString in Excel VBA and use that?
[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
<tbody>[TR]
[TD]Hi All,[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]It' been a while since I have posted an SQL query with VBA on here Xenou and you have been a massive help to me always[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]My question is, how do you write a string where I can am doing multiple statements[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]I.e[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
Code:
[TR]
[TD][COLOR=#00FF00]This part is done 1st[/COLOR][/TD]
[/TR]
[TR]
[TD]
call master.drop_table ('drop table MI166_A')[/TD]
[/TR]
[TR]
[TD];[/TD]
[/TR]
[TR]
[TD][COLOR=#00FF00]This part is done 2nd[/COLOR]
[/TD]
[/TR]
[TR]
[TD]create table MI166_A as[/TD]
[/TR]
[TR]
[TD]([/TD]
[/TR]
[TR]
[TD]select /*+ PARALLEL(a,32) */ [/TD]
[/TR]
[TR]
[TD] *[/TD]
[/TR]
[TR]
[TD]from CIS.TVP068ACTIVITY a[/TD]
[/TR]
[TR]
[TD]where TS_COMPLETED is null[/TD]
[/TR]
[TR]
[TD])[/TD]
[/TR]
[TR]
[TD];[/TD]
[/TR]
[TR]
[TD][COLOR=#00FF00]This Part is done 3rd[/COLOR]
[/TD]
[/TR]
[TR]
[TD]create index IDX_MI166_A1 on MI166_A (NO_ACCOUNT, CD_COMPANY_SYSTEM)[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD];
[COLOR=#00FF00]This Part is done last[/COLOR]
[/TD]
[/TR]
[TR]
[TD]create index IDX_MI166_A2 on MI166_A (NO_EMPL_ASSGN, CD_COMPANY_SYSTEM)[/TD]
[/TR]
[TD][/TD]
[/TR]
[TR]
[TD]So in essence, I am running 1 statement if you like and all of the statements get run one after another[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Now how can I put the above into a an SqlString in Excel VBA and use that?
Code:
Sub ADO_SQL()
Dim cmd As ADODB.Command
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim strDB As String
Dim strlogin As String
Dim strpass As String
Dim connection_string As String
Dim ws As Worksheet
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection
Set ws = Worksheets("Sheet1")
'Loads database login details
strDB = "MVWLDM" '(Schema Details)
strlogin = "Test1" '(MyLogin UserId)
strpass = "password" '(MyPassword)
'//Connection string 'Provider
connection_string = "Provider=OraOLEDB.Oracle.1;" & "Password=" & strpass & "; User ID=" & strlogin & ";Data Source=" & strDB & "; Persist Security Info=True"
sSQL = [B][COLOR=#00FF00]???????[/COLOR][/B]
'//Open a connection with the connection string
With cn
.ConnectionString = connection_string
.Open
End With
'//Run SQL Command
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = sSQL
.Execute
End With
cn.Close
'//Cleanup (optional)
Set cn = Nothing
Set cmd = Nothing
strSQL = ""
End Sub
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]