I've got a sequential file that I've got all ready to load into my DB except the rows in the sequential file don't have a key_id. I need to generate one for every row that gets loaded and I need the first value to be the next highest value based on the highest key already in the table.
Now I know I could get this key and put it in a hash file in a different stage and then incremement that hash file but is there a way to do it in my existing stage??
Any help is greatly appreciated, thanks
Getting next key value based on highest key in target table?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
No. You have to persist the highest value, either locally when you run your job (use an Aggregator stage with the Last function or Max function on the key column) or by select max(key) from table; before the next run.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Or
you can also do it in the transformer stage.
Get the max from the table, store it in a hash file and pass that value into the tranformer. Specify two stage variables
your key value will be var1 in the above code.
i hope this helps
cheers.
you can also do it in the transformer stage.
Get the max from the table, store it in a hash file and pass that value into the tranformer. Specify two stage variables
Code: Select all
var1 = IF (in.MAX=Var2) THEN Var1+1 ELSE in.MAX +1
var2 = in.MAX
i hope this helps
cheers.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
You could consider in the initialization of a stage variable using an ExecSH/ExecDOS call to a database command line program like sqlplus to issue SELECT MAX(... SQL statement on your table and return the answer as the initialization value. Increment your stage variable from there with each use.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
hmm, that might help, I'll try that, thanks!DSguru2B wrote:Or
you can also do it in the transformer stage.
Get the max from the table, store it in a hash file and pass that value into the tranformer. Specify two stage variablesyour key value will be var1 in the above code.Code: Select all
var1 = IF (in.MAX=Var2) THEN Var1+1 ELSE in.MAX +1 var2 = in.MAX
i hope this helps
cheers.