Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default Big Honkin' Query

I normally use SQL queries in my VBA code like this:


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

cn.Open "Driver={SQL
Server};Server=ServerName;Database=DBNAME;Uid=x;Pw d=y"

sql = "SELECT * FROM Table1 WHERE Field1 = 'MyValue'"

rs.Open sql, cn


It passes the string to the datebase and returns the results as a
recordset. But now I have a query so large that it can not easily be
contained as a string in my VBA. Is there a way to refer to a text file
where it is kept, or some other idea?

tod

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Big Honkin' Query

I feel your pain... I have run into the same thing. I solved this by passing
a concatenated string. So instead of having a varialbe called sql you end up
with 3 varaibles like

strSelect = "SELECT * "
strFrom = "FROM Table1 "
strWhere = "Field1 = 'MyValue'"

rs.Open strSelect & strFrom & strWhere , cn

Which oddly enough works...

HTH

"Tod" wrote:

I normally use SQL queries in my VBA code like this:


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

cn.Open "Driver={SQL
Server};Server=ServerName;Database=DBNAME;Uid=x;Pw d=y"

sql = "SELECT * FROM Table1 WHERE Field1 = 'MyValue'"

rs.Open sql, cn


It passes the string to the datebase and returns the results as a
recordset. But now I have a query so large that it can not easily be
contained as a string in my VBA. Is there a way to refer to a text file
where it is kept, or some other idea?

tod


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Big Honkin' Query

How about a stored procedure in the database itself?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Tod" wrote in message
ups.com...
I normally use SQL queries in my VBA code like this:


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

cn.Open "Driver={SQL
Server};Server=ServerName;Database=DBNAME;Uid=x;Pw d=y"

sql = "SELECT * FROM Table1 WHERE Field1 = 'MyValue'"

rs.Open sql, cn


It passes the string to the datebase and returns the results as a
recordset. But now I have a query so large that it can not easily be
contained as a string in my VBA. Is there a way to refer to a text file
where it is kept, or some other idea?

tod



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
Convert hard coded query criteria to Parameter Query Melanie[_2_] Excel Discussion (Misc queries) 0 July 15th 08 09:59 PM
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Importing Data via Web Query - Can values be passed to query? [email protected] Excel Discussion (Misc queries) 5 May 9th 06 06:21 PM
Edit Query from Excel will not open query in MSQuery Michelle Excel Programming 0 February 21st 05 03:59 PM
Problem with .Background Query option of ODBC Query Shilps Excel Programming 0 April 19th 04 06:41 AM


All times are GMT +1. The time now is 06:13 AM.

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"