Solved

Tables and Queries

Posted on 2002-05-31
6
200 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

13 Experts available now in Live!

Get 1:1 Help Now