LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Extremely long SQL Array

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How fix a too long array function KalleH Excel Worksheet Functions 5 August 24th 09 04:55 PM
Morefunc VSort with array of long output RB Smissaert Excel Programming 0 May 12th 06 05:02 PM
Transpose Function not Working with Long Array Elements Ngan Excel Programming 1 August 9th 05 08:59 PM
Array Formulas take waaaay too long... belly0fdesire Excel Worksheet Functions 7 August 8th 05 10:11 PM
Challenging long ARRAY formula needed - Can this be done? quartz[_2_] Excel Programming 7 November 30th 04 04:03 PM


All times are GMT +1. The time now is 03:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"