• It might even be from a _new_ mainframe db

    create function dbo.fnGetNextRecNo(@company xx, @customer xx, @glperiod xx, @transaction)
    returns smallint
    as
        begin
            declare @NewRecNo smallint, @recno int
            select @recno =max(recno) + 1
            from _B
            where company = @company
               and customer = @customer
               and glperiod = @glperiod
               and transaction = @transaction
             
            set @NewRecNo = isnull(@RecNo , 1) -- ?? where do you want to start today
           
            if @NewRecNo < (-32768)  or @NewRecNo > 32767
            begin
                  -- Now what ??? 
                  set @NewRecNo = (-32768)
            end
            return @NewRecNo
        end
    go

    -- grant when needed

    insert into _B (col_list)

    select company,customer,glperiod,transaction, dbo.fnGetNextRecNo(company,customer,glperiod,transaction),...

    from _A

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me