Solved

Query from a query

Posted on 1998-06-02
8
152 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

22 Experts available now in Live!

Get 1:1 Help Now