Hi. I'm not sure if I can ask this question here but I guess I'm going to any way.
It's basically a procedure I'm doing in MySQL for my program. I'd like to copy rows in a table but I need to change the values in a certain field as they need to be unique.
I get the unique keys from another table where I hold the next unique key to be used and use a custom function to increment it.
I copy the rows needed into a temporary table where i can work with it and change the values, I am hoping there is a way of going through each row and giving each one it's new unique key, I wanted to do it through a while loop. Will this work in any way? (my only problem is I don't know how to go from one row to another)
Thanks in advance
Remko Strating
Ranch Hand
Joined: Dec 28, 2006
Posts: 893
posted
0
You could use a cursor for going through all the records
If there is some reason you can not alter the table... use a variable to set your max-key and set its value to the max(old_value) in your old table + 1 (or some number of your choosing).
Dylan Margoczi
Ranch Hand
Joined: Jul 12, 2007
Posts: 38
posted
0
Thanks Remko, I used cursors and all is working perfectly now. Thanks a lot.
Paul, I'm not 100% sure on what you are trying to show me there. But from what I pick up, I can't do that because I want it to be Dynamic in a way that I can add columns to the tables later on and not have to worry about adding it in to the procedure. I also don't like using SQL's auto increment because I find it too hard to maintain in my program. My values that need to be incremented have strings in them too and so I had to create my own function.
Thanks guys.
Paul Campbell
Ranch Hand
Joined: Oct 06, 2007
Posts: 338
posted
0
Originally posted by Dylan Margoczi: Thanks Remko, I used cursors and all is working perfectly now. Thanks a lot.
Paul, I'm not 100% sure on what you are trying to show me there. But from what I pick up, I can't do that because I want it to be Dynamic in a way that I can add columns to the tables later on and not have to worry about adding it in to the procedure. I also don't like using SQL's auto increment because I find it too hard to maintain in my program. My values that need to be incremented have strings in them too and so I had to create my own function.
Thanks guys.
Hey Dylan,
I think I completely misinterpreted your issue... my mistake. I'm glad the issue is resolved.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.