Solved

afterscroll queery

Posted on 2007-03-20
6
247 Views
Last Modified: 2010-04-05
I have 3 tables.'Companies','Subcompanies' and 'Workers'

1st one :
CompanyID
CompanyName

second :
CompanyID
SubcompanyID
SubcompanyName

Third :
CompanyID
SubcompanyID
WorkerID
Workername


On afterscroll of the 1st table
with ABSQuery1 do
 begin
   Close;
   if ABSTable1.FieldByName('CompanyID').AsString <> '' then
   begin
   SQL.Text:= 'select * from Subcompanies where CompanyID = ' +
       ABSTable1.FieldByName('CompanyID').AsString;
        Open;
     end;
 end;

However now I need to have workers displayed.
I want displayed only those who's CompanyID and SubcompanyID match.
That means another queery on afterscroll of the first ABSQueery1.
How is the sql supposed to look like ??
0
Comment
Question by:Vrtnar
  • 4
6 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 18756133
select * from workers where CompanyID = value_selected_in1table AND SubcompanyID = value_selected_in2table

ziolko.
0
 
LVL 6

Expert Comment

by:bokist
ID: 18756191
Hi vrtnar !

Try this way:

 if ABSTable1.FieldByName('CompanyID').AsString <> '' then
   begin
   Sql.Clear;
   Sql.add('select c.companyId, companyName, s.subcompanyId, subcompanyName, workerId, Workername');  
   Sql.add('  from companies c,  subcompanies s, workers w');
   Sql.add('where c.companyId = :co');
   Sql.add('    and c.companyId = s.companyId');
   Sql.add('    and s.companyId = w.companyId');
   Sql.add('    and s.subcompanyId = w.subcompanyId');
   Parambyname('co').asstring := ABSTable1.FieldByName('CompanyID').AsString;
   Open;

Not tested, just from head!!

regards
  steve


   
0
 

Author Comment

by:Vrtnar
ID: 18756286
if ABSQuery1.FieldByName('SubcompanyID').AsString <> '' then
   begin
   SQL.Text:= 'select * from workers  where companyID = ABSTable1.FieldByName('companyID').AsString AND ABSQuery1.FieldByName('SubcompanyID').AsString  ;

I get :
[Error] Unit1.pas(191): Missing operator or semicolon
[Error] Unit1.pas(192): Expression expected but 'AND' found
[Error] Unit1.pas(192): Unterminated string
[Error] Unit1.pas(193): Missing operator or semicolon
[Error] Unit1.pas(317): Statement expected but 'PROCEDURE' found
[Fatal Error] Project1.dpr(8): Could not compile used unit 'Unit1.pas'
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 21

Accepted Solution

by:
ziolko earned 125 total points
ID: 18756332
SQL.Text:= 'select * from workers  where companyID = ' + ABSTable1.FieldByName('companyID').AsString + ' AND SubcompanyID = ' +ABSQuery1.FieldByName('SubcompanyID').AsString

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18756339
...or

SQL.Text := Format('select * from workers where CompanyId=%d and SubCompanyID=%d', [ABSTable1.FieldByName('companyID').AsInteger, ABSQuery1.FieldByName('SubcompanyID').AsInteger]);

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18756376
btw. cursor position in ABSTable and ABSQuery doesn't correspond with index of record selected in DBGrid or any other component that you use to display data, go to Demos folder and look for Master/Detail sample

ziolko.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically Created Query 3 62
CheckListBox usage 3 72
Sending files from  idTcpServer Socket to idTcpClient 2 44
Twebbrowser add css to the header 3 29
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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