Solved

Query from a query

Posted on 1998-06-02
8
155 Views
Last Modified: 2010-04-06
Is it possible to use the result from a query in another TQuery object.  For instance, Have a query that returns a data set.  Then have another query that returns the sum of one of the columns in the first dataset?  

I'm trying to avoid having the same query in multiple places!

Roger Webb
0
Comment
Question by:Whytboy
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1349707
Sure, why not?
0
 

Author Comment

by:Whytboy
ID: 1349708
And that would be accomplished .... how??


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1349709
Ooops, sorry misread your question, don't know if that's possible.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Accepted Solution

by:
yunic earned 150 total points
ID: 1349710
 Query1.SQL.Text:='select attr_op, attr_dolzina from meta_sif_attr';
  Query1.Open;
  Query2.SQL.Text:='select sum('+query1.fields[1].fieldname+') from meta_sif_attr';
  query2.Open;
  writeln(Query2.fields[0].AsString);


0
 

Author Comment

by:Whytboy
ID: 1349711
Problem with that is that if you include a where clause so make query1 a subset of data.. you would have to include the where clause in query2 as well...
0
 

Expert Comment

by:yunic
ID: 1349712
that's true.

one solution would be to copy all text from query1 to query2 replacing just fields between 'select ' and ' from'.

actually it was meant to be used that way especially if query is joining more tables.



0
 

Expert Comment

by:yunic
ID: 1349713
so it would look like this

query2.sql.text:='select sum('+query1.fields[1].fieldname+') '+
  copy(query1.sql.text, pos('from',query1.sql.text),
    length(query1.sql.text)-pos('from',query1.sql.text));

check syntax, i wrote it know, didn't checked
0
 

Author Comment

by:Whytboy
ID: 1349714
Adjusted points to 150
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

816 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

8 Experts available now in Live!

Get 1:1 Help Now