DECLARE @RC int
DECLARE @O_iOUTMasterNumber int
DECLARE @O_iErrorState int
SELECT @O_iOUTMasterNumber ='',
@O_iErrorState =0
EXECUTE @RC = [dbo].[taSopGetMasterNumber]
@O_iOUTMasterNumber OUTPUT
,@O_iErrorState OUTPUT
SELECT @O_iOUTMasterNumber ,
@O_iErrorState
If eConnect is not installed, here's our own implementation
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'DD_SOPGetNextMaster'
AND type = 'P')
DROP PROCEDURE DD_SOPGetNextMaster
GO
CREATE PROCEDURE DD_SOPGetNextMaster
@intMaster int output
AS
declare @bOkToExit int
--initialize
set @bOkToExit = 0
begin tran
while @bOkToExit = 0 begin
set @bOkToExit = 1 --assume success
--get the next master number
select @intMaster = nxtmstno
from sop40100 with (nolock)
--increment the next master number
update sop40100 set nxtmstno = @intMaster + 1
--see if the number that we're going to use is in use
--if it is, loop around again
if exists (select mstrnumb
from sop10100 with (nolock)
where mstrnumb = @intMaster)
set @bOkToExit = 0
if exists (select mstrnumb
from sop30200 with (nolock)
where mstrnumb = @intMaster)
set @bOkToExit = 0
if exists (select intMasterNumber
from ngboed..masterorders with (nolock)
where intMasterNumber = @intMaster)
set @bOkToExit = 0
end
commit tran
GO
grant all on DD_SOPGetNextMaster to public
--select nxtmstno,* from sop40100
-- update sop40100 set nxtmstno = 139000
--select intmasternumber from ngboed..masterorders where vchrcompanyidgp = 'stone' order by 1 desc