Solved

Tables and Queries

Posted on 2002-05-31
6
204 Views
Last Modified: 2010-04-04
Hi,

I need some help with regards to Paradox tables and SQL queries.

I am developing a database solution that scans a table of information for certain criteria.
The criteria is returned and populated in a dbGrid component. OK up to now.

With the information returned, I want to fill in a field with a value. But only fill in the field on the records that have been returned by my query.

How can I accomplish this?
Any help would be great.

Many Thanks
0
Comment
Question by:HotRod40
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:bes67
ID: 7046641
Hi,

as far as I understand you have 2 components: TTable and TQuery (with the select on the same table with some conditions (where clause)). And your Query's result set is not "Live".
It seems to me that you can intclude in select field (or fields) that compose the primary index of a table and then make something like this:

Query.First;
while not Query.Eof do
begin
  if Table.Locate('Field_1', Query.FieldByName('Field_1').Value,[]) then
    Table.FieldByName('Field_2').Value := aValue;
  Query.Next;
end;

bes67
0
 

Author Comment

by:HotRod40
ID: 7046706
I have a table which has a filter set on it.
When the table is opened the filter brings up all records where the FirstInvoice is set to True.
FirstInvoice is a field in my table.
The filter is: FirstInvoice = 'True'

The records where the FirstInvoice is set to True are shown in a dbGrid component.

I want to amend another field called Flag on each record and populate it with a value, but I only want to update the records that have been retrieved.

I have heard that you can use a ResultSet or something??

Hope this helps
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7046715
update tablename set fieldname = value where ...
(the whereclause u used for the query)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7046718
more specific to yours

update tablename set flag = avalue where firstinvoice = true
0
 
LVL 1

Expert Comment

by:bes67
ID: 7046773
Try something like this

Drop TQuery on your form with SQL property set to

UPDATE TABLE_NAME SET
FLAG = :Val
WHERE FIRSTINVOICE = 'True'

Database property of TQuery must be the same as the one in TTable

write somewhere in you code

Query.ParamByName('Val').Value := aValue;
Query.ExecSQL;
Table.DisableControls;
try
Table.Refresh;
finally
Table.EnableControls;
end;
0
 
LVL 1

Accepted Solution

by:
bes67 earned 75 total points
ID: 7046804
Try something like this

Drop TQuery on your form with SQL property set to

UPDATE TABLE_NAME SET
FLAG = :Val
WHERE FIRSTINVOICE = 'True'

Database property of TQuery must be the same as the one in TTable

write somewhere in you code

Query.ParamByName('Val').Value := aValue;
Query.ExecSQL;
Table.DisableControls;
try
Table.Refresh;
finally
Table.EnableControls;
end;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Delphi application Soap connection 5 118
Controlled Assessment GCSE - desperate help needed 4 100
creating threads in delphi 1 130
Dynamically Created Query 3 62
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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