Hello,
I have this bit of code which is supposed to pull 6 lines of data, but it fails. Any thoughts as to why? The code keeps breaking execution. (I've tried both DAO and ADO, below is the ADO)
Thanks,
B
Option Explicit
Sub OpenDB()
'Dim db As ADODB.Database
'Dim ws As ADODB.Workspace
Dim rst As ADODB.Recordset
Dim conn As ADODB.Connection
Dim ConnectionString As String
Dim Querystring As String
Dim strSQL As String
Dim luserName As String
Dim lpassword As String
Dim account As String
Dim startDt As String
Dim endDt As String
Dim strSQL_2 As String
Dim strSQL_3 As String
Dim strSQL_4 As String
Dim strSQL_5 As String
luserName = Range("userName")
lpassword = Range("password")
account = Range("account")
startDt = CStr(Format(Range("start").Value, "d-mmm-yyyy"))
endDt = CStr(Format(Range("end").Value, "d-mmm-yyyy"))
strSQL = "with " & _
"accounts as ( " & _
6 Lines Here
" ), " & _
"" & _
"dates as ( " & _
5 Lines Here
" ) , " & _
" " & _
"AT as ( " & _
5 Lines Here
" ), " & _
"" & _
"SR as ( "
strSQL_2 = strSQL & "
4 Lines
" ) , " & _
" " & _
"AR as ( " & _
6 Lines
" ), " & _
"" & _
" " & _
"P as ( " & _
8 Lines
" ), "
strSQL_3 = strSQL_2 & "close_price as ( " & _
10 Lines
), " & _
" " & _
"FVP as ( " & _
9 Lines
" ), " & _
"" & _
"OP as ( "
strSQL_4 = strSQL_3 &
14 Lines
" )," & _
" " & _
"MV as ( " & _
12 Lines
strSQL_5 = strSQL_4 &
Final Select and 15 Lines
The above query is about 10 tables (made using "with as", 3999 characters and returns 8 lines of data in PL/SQL in about 20 seconds.
Set conn = New ADODB.Connection
conn.Open "Data Source="name";UID=" & luserName & ";PWD=" & lpassword & ""
Set rst = New ADODB.Recordset
rst.Open strSQL_5, conn
Sheets("Data").Select
Cells(2, 1).CopyFromRecordset rst
rst.Close
conn.Close
End Sub
Why does such a large query fail? Changing the timeout only crashes Excel. Thanks for the help.
I have this bit of code which is supposed to pull 6 lines of data, but it fails. Any thoughts as to why? The code keeps breaking execution. (I've tried both DAO and ADO, below is the ADO)
Thanks,
B
Option Explicit
Sub OpenDB()
'Dim db As ADODB.Database
'Dim ws As ADODB.Workspace
Dim rst As ADODB.Recordset
Dim conn As ADODB.Connection
Dim ConnectionString As String
Dim Querystring As String
Dim strSQL As String
Dim luserName As String
Dim lpassword As String
Dim account As String
Dim startDt As String
Dim endDt As String
Dim strSQL_2 As String
Dim strSQL_3 As String
Dim strSQL_4 As String
Dim strSQL_5 As String
luserName = Range("userName")
lpassword = Range("password")
account = Range("account")
startDt = CStr(Format(Range("start").Value, "d-mmm-yyyy"))
endDt = CStr(Format(Range("end").Value, "d-mmm-yyyy"))
strSQL = "with " & _
"accounts as ( " & _
6 Lines Here
" ), " & _
"" & _
"dates as ( " & _
5 Lines Here
" ) , " & _
" " & _
"AT as ( " & _
5 Lines Here
" ), " & _
"" & _
"SR as ( "
strSQL_2 = strSQL & "
4 Lines
" ) , " & _
" " & _
"AR as ( " & _
6 Lines
" ), " & _
"" & _
" " & _
"P as ( " & _
8 Lines
" ), "
strSQL_3 = strSQL_2 & "close_price as ( " & _
10 Lines
), " & _
" " & _
"FVP as ( " & _
9 Lines
" ), " & _
"" & _
"OP as ( "
strSQL_4 = strSQL_3 &
14 Lines
" )," & _
" " & _
"MV as ( " & _
12 Lines
strSQL_5 = strSQL_4 &
Final Select and 15 Lines
The above query is about 10 tables (made using "with as", 3999 characters and returns 8 lines of data in PL/SQL in about 20 seconds.
Set conn = New ADODB.Connection
conn.Open "Data Source="name";UID=" & luserName & ";PWD=" & lpassword & ""
Set rst = New ADODB.Recordset
rst.Open strSQL_5, conn
Sheets("Data").Select
Cells(2, 1).CopyFromRecordset rst
rst.Close
conn.Close
End Sub
Why does such a large query fail? Changing the timeout only crashes Excel. Thanks for the help.