Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating an ADO Table through SQL

Status
Not open for further replies.

PaidtheUmpire

Programmer
Jan 4, 2004
105
AU
How can you update a database through code in Delphi. Not by entering data yourself.

What i have is a table of X people, with attributes: NAME, LOCATION and VALUE.
Is it possible to set up some code that firstly selects ONLY those people that are in USA [Location = 'USA'], and then using a "random" generated number for each person, update the Value attribute?

Example:
NAME LOCATION VALUE
Rick USA 65
Bill USA 12
Adam ENG 8

So the code would select only Rick and Bill then generate a random variable for each (eg. 9 and 3). A variable of less than 5, would mean that the variable in VALUE would go up 10, while a value of 6 or more would leave the VALUE unchanged.

End of Example:
NAME LOCATION VALUE
Rick USA 65
Bill USA 22 (Up ten from 12)
Adam ENG 8

 
What part do you need help with?
The initial query to SELECT where location='USA'?
Generating a random number?
The update query to UPDATE where name=:NAME?
What do you have so far?
What database are you using?

With SQL Server, I would drop two TADOQuery components on a data module and set up a loop to process each name while not EOF. With another database, depending on how much data are involved, I would gather all of the data in a collection (TObjectList) and then loop thru the collection. There are many other ways of doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top