Solved

ADO - 2 part sql statement

Posted on 2004-08-27
3
219 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

717 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