D
Diana
Okay, here's the final stretch to the home-run: I have a VBA Module
that has an extremely long SQL query array. Normally this wouldn't be
too much of an issue, but unfortunately, I cannot make any more "line
continuations", and still have more SQL query information to add to
the Array (yikes).
So what can I do with this array to make it "fit" all of the extra
information...or do I have to reformat my entire query (I don't mind
doing that one bit if I knew how)? I've heard that you can construct
the SQL into strings and then "join" them together, but each time I
try, I just get a bunch of errors and end up going back to my original
query format.
Could I possibly get a hand with this, or is it just too much to
handle? =P
I'll post what I have with some of the SQL Array deleted (shown
by ...) so it won't look too terribly disgusting (and yes, each of the
line continuations has just under 255 characters each).
Thanks in advance!
~~~~~~~~~~~~~~~~~~~~
Sub Connect3()
Dim cellValue1 As String
Dim cellValue2 As String
Dim sh As Worksheet
For Each sh In Sheets(Array("Inventory Analyzer", "Last 30 Days",
"Last 90 Days", "Last 180 Days", "Last 360 Days"))
cellValue1 = sh.Range("B3").Value
cellValue2 = sh.Range("B4").Value
With sh.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=Everest;Description=Everest
data;UID=sa;PWD=SQL14mibank;APP=Microsoft Office
2003;WSID=ANDYHP5300;DATABASE=EVEREST_VGI;Network=DBMSS" _
), Array("OCN")), Destination:=sh.Range("A8"))
.CommandText = Array( _
"SELECT DISTINCT ITEMS.ITEMNO, ... FROM X_STK_AREA LEFT OUTER
JOIN ITEMS ON " _
, _
"(X_STK_AREA.ITEM_NO = ITEMS.ITEMNO) ... LEFT OUTER JOIN
(SELECT X_INVOIC.ITEM_CODE AS " _
, _
"[ITEMSUM0], sum(X_INVOIC.QTY_SHIP) AS [Invoice_Sum] ... " _
, _
"(INVOICES.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') GROUP BY X_INVOIC.ITEM_CODE) ... " _
, _
"FROM X_INVOIC INNER JOIN INVOICES ON (X_INVOIC.ORDER_NO =
INVOICES.DOC_NO) ... " _
, _
"(INVOICES.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') GROUP BY X_INVOIC.ITEM_CODE) ... " _
, _
"JOIN PO ON (PO.DOC_NO = X_PO.ORDER_NO) ... " _
, _
"OUTER JOIN (SELECT X_PO.ITEM_CODE AS [QTYRECI], ..." _
, _
"(PO.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') ... " _
, _
"(X_STK_AREA.AREA_CODE='MAIN') AND (PO.ORDER_DATE BETWEEN '" &
cellValue1 & "' AND '" & cellValue2 & "')) ORDER BY ITEMS.ITEMNO")
.Name = "Query from Venom Everest1"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
Next
End Sub
that has an extremely long SQL query array. Normally this wouldn't be
too much of an issue, but unfortunately, I cannot make any more "line
continuations", and still have more SQL query information to add to
the Array (yikes).
So what can I do with this array to make it "fit" all of the extra
information...or do I have to reformat my entire query (I don't mind
doing that one bit if I knew how)? I've heard that you can construct
the SQL into strings and then "join" them together, but each time I
try, I just get a bunch of errors and end up going back to my original
query format.
Could I possibly get a hand with this, or is it just too much to
handle? =P
I'll post what I have with some of the SQL Array deleted (shown
by ...) so it won't look too terribly disgusting (and yes, each of the
line continuations has just under 255 characters each).
Thanks in advance!
~~~~~~~~~~~~~~~~~~~~
Sub Connect3()
Dim cellValue1 As String
Dim cellValue2 As String
Dim sh As Worksheet
For Each sh In Sheets(Array("Inventory Analyzer", "Last 30 Days",
"Last 90 Days", "Last 180 Days", "Last 360 Days"))
cellValue1 = sh.Range("B3").Value
cellValue2 = sh.Range("B4").Value
With sh.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=Everest;Description=Everest
data;UID=sa;PWD=SQL14mibank;APP=Microsoft Office
2003;WSID=ANDYHP5300;DATABASE=EVEREST_VGI;Network=DBMSS" _
), Array("OCN")), Destination:=sh.Range("A8"))
.CommandText = Array( _
"SELECT DISTINCT ITEMS.ITEMNO, ... FROM X_STK_AREA LEFT OUTER
JOIN ITEMS ON " _
, _
"(X_STK_AREA.ITEM_NO = ITEMS.ITEMNO) ... LEFT OUTER JOIN
(SELECT X_INVOIC.ITEM_CODE AS " _
, _
"[ITEMSUM0], sum(X_INVOIC.QTY_SHIP) AS [Invoice_Sum] ... " _
, _
"(INVOICES.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') GROUP BY X_INVOIC.ITEM_CODE) ... " _
, _
"FROM X_INVOIC INNER JOIN INVOICES ON (X_INVOIC.ORDER_NO =
INVOICES.DOC_NO) ... " _
, _
"(INVOICES.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') GROUP BY X_INVOIC.ITEM_CODE) ... " _
, _
"JOIN PO ON (PO.DOC_NO = X_PO.ORDER_NO) ... " _
, _
"OUTER JOIN (SELECT X_PO.ITEM_CODE AS [QTYRECI], ..." _
, _
"(PO.ORDER_DATE BETWEEN '" & cellValue1 & "' AND '" &
cellValue2 & "') ... " _
, _
"(X_STK_AREA.AREA_CODE='MAIN') AND (PO.ORDER_DATE BETWEEN '" &
cellValue1 & "' AND '" & cellValue2 & "')) ORDER BY ITEMS.ITEMNO")
.Name = "Query from Venom Everest1"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
Next
End Sub