?
Solved

ADO - 2 part sql statement

Posted on 2004-08-27
3
Medium Priority
?
220 Views
Last Modified: 2013-11-23
Using ADO connected to a SQL Server database I want to populate a recordset with a 2 part query. In a simplified version, something like this:

rs.Open "Select * Into #Temp From ATable  Select * From #Temp"

What I want returned to the recordset is the contents of the temp table. When I run this I don't get an error but the recordset state is closed. I know that I could add a stored procedure to the database but want to do this through ado if possible.

Any ideas?
0
Comment
Question by:jgv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Expert Comment

by:rinksno1
ID: 11918957
as you said you want all the records from the temp table
use


connectionstring="provider=sqloledb.1;uid=sa;pwd=;data source=servername;initial catalog=database1"
rs.ActiveConnection = ConnectionString
rs.CursorLocation = adUseClient

rs.open "Select * from temp", , dOpenStatic, adLockReadOnly

now iterate through the recordset

***********

rinks
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 11918972
Use this:

rs.Open "SET NOCOUNT ON Select * Into #Temp From ATable  Select * From #Temp SET NOCOUNT OFF"
0
 
LVL 12

Author Comment

by:jgv
ID: 11919009
Thanks emoreau, that did it. Now that you pointed out the nocount it makes sense. I've been caught by this in the past; just didn't think of it in this case.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question