Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Data Objects - Sub Query as Source

Status
Not open for further replies.

SkipVought

Programmer
Dec 4, 2001
47,487
US
Suppose I have a query like this...
Code:
Select
  A.F1
, Sum(B.F1)
From Table1 A
, 
(
Select 
  F1
, F2
From Table2
) B
Where A.F2=B.F2
Group By A.F1
But I want to accomplish it with separate recordsets...
Code:
sSQL = "Select "
sSQL = sSQL & "  F1 "
sSQL = sSQL & ", F2 "
sSQL = sSQL & "From Table2 "

rst1.Open sSQL, cnn, adOpenForwardOnly

sSQL = "Select "
sSQL = sSQL & "  A.F1
sSQL = sSQL & ", Sum(B.F1)
sSQL = sSQL & "From Table1 A
sSQL = sSQL & ", 
sSQL = sSQL & "([b]
'somehow use rst1 here.  I know I can use it like [highlight]rst1.Source[/highlight], but is there another method?[/b]
sSQL = sSQL & ") B
sSQL = sSQL & "Where A.F2=B.F2
sSQL = sSQL & "Group By A.F1

rst2.Open sSQL, cnn, adOpenDynamic
In reality, rst2 is a summary of rst1, and several other queries as well.

My objective is that after I post the resultset for rst2, I give the user the ability to drill down into rst1 and other detail resultsets that are summarized in rst2.


Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Not quite what you were after Skip, but I've seen this done in apps by only issuing code to execute rst1, then using recordset filters in Access or summary rows in Excel pivot tables to display the summary information.

You can then open the detail that the user requests without running a query to open the detail information.

John
 





Thanks, John.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top