Thanks for your reply.
Is there something I have to do to make "Params[0]" etc work? As of now, I get "undeclared identifier: 'Params'".
Main Topics
Browse All TopicsHello,
I have a query that picks out 1 random result from a table based on different factors; however, after that result is picked the field "Klubbint" needs to be updated to intklubb.caption.
How to achieve this?
Tried some different methods, but failed to succeed and often got the msg "cannot update a complex query with more then one table." Any ideas(using Firebird)?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
oh ... i assumed (wrong) spelare to be a TQuery or a TQuery descendant and beside that I think i`ve misread you question so ignore my previous post.
now is that spelare object will be a TQuery then you can attach a TUpdateSQL to modify the content of the TQuery and only affect the table that you need.
"after that result is picked the field "Klubbint" needs to be updated to intklubb.caption"
Are you trying to do this:
intklubb.caption := Spelare.Fieldbyname('Klubb
or are you trying to do this:
//Query Spelare has already been populated with a result set
Spelare.First;
While Spelare.eof = false do
begin
Spelare.Edit;
Spelare.Fieldbyname('Klubb
Spelare.Post;
Spelare.Next;
end;
Or is Klubbint not part of your original query and you have to update it using a separate Query? In that case you will need an ID to refer to the records you want. You SQL would say something like UPDATE MyTable SET MyTable.Klubbint = ' + intklubb.caption + ' WHERE RecordID = 123
Query has already been populated with a result set (1 record). However, even if I do add that code nothing seems to happen.. the Klubbint field is still empty (even after a refresh).
Intklubb.caption is a string, but changing "value" into "asstring" etc made no difference. I do get an error when using "strtoint" and value, but when correcting this it just seems to skip by the code.
"However, even if I do add that code nothing seems to happen.. the Klubbint field is still empty (even after a refresh)."
That's strange... Perhaps it is being updated in the database but your dataset isn't refereshing the data properly. You really should have Primary Keys and IDs in your tables so that you can update records that way in some cases. Also in some cases Query's can return read-only resultsets which would definitely prevent you from editing records. I don't think that's the case here because you would get an error.
So are you getting that error about complex update or something like that? What I think is happening is this: in some databases you can't send an UPDATE statement(s) with SELECT statements -- the one is to request data the other is to set data. Your Zeoslib components do everything using SQL behind the scenes. I'm guess that when you try to update your table the SQL that it sends is too complex.
So... your best bet is to change the Klubbint field using a separate update query, instead of editing the dataset.. I also think that this will be the "best practise" way of doing things because best practise is to not post to a dataset while you're busy iterating/cycling through it (because your dataset will have an index and for example if you change a record that was at the beginning, and the index now says it should go to the end, it will change the order of your records).
So, you will need to do separate SQL update statements. You will need a primary key / ID to refer to the record(s) you want to update.
I do not know the field structure of your table. Does it have a primary key / ID field? and if not can you create one?
If you really can't create a primary key, then the WHERE part of your UPDATE statement will just have to be really long, listing all of your fields, something like this:
UPDATE myTable SET MyTable.KlubbInt = " + intklubb.caption
+ ' WHERE MyTable.Field1 = ' + Spelare.Fieldbyname('Field
+ ' and WHERE MyTable.Field2 = ' + Spelare.Fieldbyname('Field
+ ' and WHERE MyTable.Field3 = ' + Spelare.Fieldbyname('Field
+ ' and WHERE MyTable.Field4 = ' + Spelare.Fieldbyname('Field
+ ' and WHERE MyTable.Field5 = ' + Spelare.Fieldbyname('Field
+ ' and WHERE MyTable.Field6 = ' + Spelare.Fieldbyname('Field
etc etc etc
By the way my UPDATE SQL might not be 100% but at least you get the idea.
As long as the combination of fields in your WHERE statement will make sure that the correct record is updated then it will work. It is not best practise at all. This is the reason why they teach you to create an unique ID for every record called the Primary Key. You might have 2 players with the same name, so you need a way to identify each record by itself.
I hope some of this helps
Thanks for your effort and help.
My table doesn't have any Primary key / ID, but I am trying to create one using Firebird Maestro. I have had problems with 2 players having the same name, so I feel that I really do need some kind of unique ID/Key.
Tried creating it using triggers/generator and the code below(created by FB Maestro and according to http://www.firebirdsql.org
"SQL Error: unsuccessful metadata update DEFINE GENERATOR failed attempt to store duplicate value (visible to active transactions) in unique index "RDB$INDEX_11". Error Code: -607. This operation is not defined for system tables. The SQL: /* Autoincrement for field (ID) */
CREATE GENERATOR GEN_SPELARE_ID;"
Well your code seems right, with some observations:
1) Your "with Spelare do" statement does not cycle through all its records - it will only update the Spelare table once, and only for whatever record it is currently on. If you want it to do all the records showing in the resultset then you will need to say FIRST, WHILE EOF = FALSE and NEXT etc.
2) I'm not sure why you are storing your parameters in TLabels or whatever. Normally you would just say:
SQL.Add('Update Spelare Set klubbint = ''' + MyDataSet.Fieldbyname('klu
Business Accounts
Answer for Membership
by: xr1140Posted on 2009-04-12 at 15:21:50ID: 24127164
i think this should work:
Select allOpen in new window