Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Quering a changing range SQL


I need to query several records (averaging 2,000) that change every week.
First of all Microsoft query tells me that the SQL statement is too long.
Let's say that I reduce the size of the statement to a workable size if not
other options exist,

What statement can I use to refer to every single element of a dynamic range
in the WHERE part of the SQL statement instead of typing every single one
AND, AND ?

I tried the following but obviously didnt work because it reads it as a
single item
"WHERE (MyTable.MyField= ' & Sheet2.Range("A1").CurrentRegion & "')"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Quering a changing range SQL

You can set a range variable
with sheets("sheet2")
LastColumn = .cells(1,Columns.Count).end(xltoleft).column
LastRow = .cells(Rows.count,"A").end(xlup).row
set QRange = .range(.cells(1,"A"),.cells(LastRow,LastColumn))
MyTable.MyField=QRange
end with

"LuisE" wrote:


I need to query several records (averaging 2,000) that change every week.
First of all Microsoft query tells me that the SQL statement is too long.
Let's say that I reduce the size of the statement to a workable size if not
other options exist,

What statement can I use to refer to every single element of a dynamic range
in the WHERE part of the SQL statement instead of typing every single one
AND, AND ?

I tried the following but obviously didnt work because it reads it as a
single item
"WHERE (MyTable.MyField= ' & Sheet2.Range("A1").CurrentRegion & "')"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Quering a changing range SQL

Thanks, Joel
My problem is not defining the range as a variable or making it to auto
expand;
it is querying the content of every single cell in the range.



"Joel" wrote:

You can set a range variable
with sheets("sheet2")
LastColumn = .cells(1,Columns.Count).end(xltoleft).column
LastRow = .cells(Rows.count,"A").end(xlup).row
set QRange = .range(.cells(1,"A"),.cells(LastRow,LastColumn))
MyTable.MyField=QRange
end with

"LuisE" wrote:


I need to query several records (averaging 2,000) that change every week.
First of all Microsoft query tells me that the SQL statement is too long.
Let's say that I reduce the size of the statement to a workable size if not
other options exist,

What statement can I use to refer to every single element of a dynamic range
in the WHERE part of the SQL statement instead of typing every single one
AND, AND ?

I tried the following but obviously didnt work because it reads it as a
single item
"WHERE (MyTable.MyField= ' & Sheet2.Range("A1").CurrentRegion & "')"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Quering a changing range SQL

Doesn't a multiple cell range solve your problem?

"LuisE" wrote:

Thanks, Joel
My problem is not defining the range as a variable or making it to auto
expand;
it is querying the content of every single cell in the range.



"Joel" wrote:

You can set a range variable
with sheets("sheet2")
LastColumn = .cells(1,Columns.Count).end(xltoleft).column
LastRow = .cells(Rows.count,"A").end(xlup).row
set QRange = .range(.cells(1,"A"),.cells(LastRow,LastColumn))
MyTable.MyField=QRange
end with

"LuisE" wrote:


I need to query several records (averaging 2,000) that change every week.
First of all Microsoft query tells me that the SQL statement is too long.
Let's say that I reduce the size of the statement to a workable size if not
other options exist,

What statement can I use to refer to every single element of a dynamic range
in the WHERE part of the SQL statement instead of typing every single one
AND, AND ?

I tried the following but obviously didnt work because it reads it as a
single item
"WHERE (MyTable.MyField= ' & Sheet2.Range("A1").CurrentRegion & "')"

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Quering a changing range SQL

No, here is the code for the query, notice after WHERE it is referring to a
range different from statying every single element of that range ie
WHERE (ECL.LORD= cellA1.value AND ECL.LORD= cellA2.value AND ECL.LORD=
cellA3.value and so on................. that is wath I'm trying to accomplish


With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= Cott;", Destination _
:=Range("A1"))
.CommandText = Array( _
"SELECT ECL.LCARR, ECL.LDESC, ECL.LORD, ECL.LQSHP, ECL.LUM" &
Chr(13) _
& "" & Chr(10) & "FROM PRDBPCS.PRODF.ECL ECL" & Chr(13) & "" &
Chr(10) _
& "WHERE (ECL.LORD= '" & Qrange & "')" _
& Chr(13) & "" & Chr(10) & "ORDER BY ECL.LORD, ECL.LDESC")

.Name = "Query from Cott_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Reply
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
Changing the range for averages with out changing the formula. JessLRC Excel Worksheet Functions 0 April 20th 10 03:10 PM
SQL: custom names of columns when using IIF (excel quering access database) riso Excel Programming 1 March 6th 07 02:46 AM
Excel(2007) crashes on quering for DrawingObjects selection ranga Excel Programming 1 January 23rd 07 02:57 PM
Changing Range with Months T De Villiers[_2_] Excel Programming 0 August 23rd 05 03:10 PM
Need help changing Range Todd Huttenstine[_2_] Excel Programming 3 November 30th 03 01:21 AM


All times are GMT +1. The time now is 04:31 PM.

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

About Us

"It's about Microsoft Excel"