I am a total novice in DB2. I am trying to help someone else out who is an SQL Novice.
What I am trying to do would look like this in SQL Server:
declare @MaxValue int
select @MaxValue = Max(ID_COLUMN) from MainTable
insert into MainTable (ID_COLUMN, OTHER_STUFF)
select TEMP_ID + @MaxValue, MORE_OTHER_STUFF
from TempTable
How can I do this in DB2? (Bonus points if you can tell me a way to do this so that the inserted values into ID_COLUMN just keep counting from the current max.)
Note: I see a lot of examples saying you can declare a variable like this
DECLARE myvariable int;
but that is erroring out for us. So if you use that syntax maybe you can comment on why that does not work.
What you have should work. look Here are you sure that you aren’t making a more perhiperal typo? perhaps in the start block of your proc.
sounds like you want an identity column to me something like this.
if you are coming from SQL Server/Sybase, one nice thing with DB2 identity column is that they don’t ‘jump’ like they do on the afore mentioned platforms.
If you need to know the last identity value generated, then you do something like this
thus you could probably do you need to by doing the above two SQL statements and then returning the values