Given that Max(CODE_ID) = 1006 and CODE_ID is the primary key and that....
begin
declare varCodeID integer;
select Max(CODE_ID) + 1 into varCodeID from CODE;
-- Insert Parent Code
insert into CODE(CODE_ID,PARENT_CODE_ID,CODE_NAME)
select varCodeID,1,'Example Parent';
-- snipped insertion of children
end
works as expected, why does the following fail saying that 1007 is a duplicate primary key?
begin
declare varCodeID integer;
select Max(CODE_ID) + 1 into varCodeID from CODE;
-- Insert Parent Code
insert into CODE(CODE_ID,PARENT_CODE_ID,CODE_NAME)
select varCodeID,1,'Example Parent' from CODE;
-- snipped insertion of children
end
Hoping the answer isn't too embarrassing, Paul