Solved

Query from a query

Posted on 1998-06-02
8
153 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 55
Delphi Firemonkey Need Sample for Online Shopping Example. 2 120
How to debug For loops? 3 45
control image tags in a string ? 12 111
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

16 Experts available now in Live!

Get 1:1 Help Now