Solved

ADO - 2 part sql statement

Posted on 2004-08-27
3
214 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
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 69

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now