Solved

Tables and Queries

Posted on 2002-05-31
6
205 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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