------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_OCVendor')
BEGIN
CREATE TABLE [dbo].[ut_OCVendor]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Ident] char(10) DEFAULT ' '
  ,[Server] char(20) DEFAULT ' '
  ,[DestNr] char(15) DEFAULT ' '
  ,[HostDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Name] char(80) DEFAULT ' '
  ,[Strasse] char(40) DEFAULT ' '
  ,[Plz] char(10) DEFAULT ' '
  ,[Ort] char(40) DEFAULT ' '
  ,[UseKnr] tinyint DEFAULT 0
  ,[UseUid] tinyint DEFAULT 0
  ,[UsePwd] tinyint DEFAULT 0
  ,[Knr] char(20) DEFAULT ' '
  ,[Uid] char(40) DEFAULT ' '
  ,[Pwd] char(40) DEFAULT ' '
  ,[IdsVer] char(3) DEFAULT ' '
  ,[IdsUri] char(200) DEFAULT ' '
  CONSTRAINT [Pk_OCVendor]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_OCVendor_KeyDel')
  DROP TRIGGER [dbo].[tr_OCVendor_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_OCVendor_KeyUpd')
  DROP TRIGGER [dbo].[tr_OCVendor_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_OCVendor_Keys')
  DROP TABLE [dbo].[ut_OCVendor_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Ident')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Ident] char(10) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Server')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Server] char(20) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [DestNr] char(15) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'HostDate')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [HostDate] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Name')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Name] char(80) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Strasse')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Strasse] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Plz')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Plz] char(10) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Ort')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Ort] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'UseKnr')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [UseKnr] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'UseUid')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [UseUid] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'UsePwd')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [UsePwd] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Knr')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Knr] char(20) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Uid')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Uid] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Pwd')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [Pwd] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'IdsVer')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [IdsVer] char(3) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'IdsUri')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ADD [IdsUri] char(200) NOT NULL DEFAULT ' '
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Ident')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Ident] char(10)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Server')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Server] char(20)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [DestNr] char(15)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Name')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Name] char(80)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Strasse')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Strasse] char(40)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Plz')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Plz] char(10)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Ort')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Ort] char(40)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Knr')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Knr] char(20)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Uid')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Uid] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'Pwd')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [Pwd] char(40)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'IdsVer')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [IdsVer] char(3)
END
GO
IF 200 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OCVendor' and sc.[name] = 'IdsUri')
BEGIN
  ALTER TABLE [dbo].[ut_OCVendor] ALTER COLUMN [IdsUri] char(200)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'OCVendor')
  DROP VIEW [dbo].[OCVendor]
GO
CREATE VIEW [dbo].[OCVendor] AS
  SELECT * FROM [dbo].[ut_OCVendor]
GO
CREATE TABLE [dbo].[ut_OCVendor_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(20) NOT NULL
  ,[Key01_Value] CHAR(25) NOT NULL
  ,[Key02_Value] CHAR(90) NOT NULL
  CONSTRAINT [Pk_ut_OCVendor_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_OCVendor_KeyDel] ON [dbo].[ut_OCVendor]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_OCVendor_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

CREATE TRIGGER [dbo].[tr_OCVendor_KeyUpd] ON [dbo].[ut_OCVendor]
FOR INSERT, UPDATE
AS
  SET NOCOUNT ON
  IF UPDATE([RecId]) OR UPDATE([MandId])
  BEGIN
    DELETE FROM [dbo].[ut_OCVendor_Keys] WITH (SERIALIZABLE)
    WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)

    INSERT INTO [dbo].[ut_OCVendor_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(10),[Ident])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+STR(RecId,10))
     ,UPPER(convert(char(80),[Name])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_OCVendor_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(10),[Ident])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(15),[DestNr])+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(80),[Name])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

UPDATE [dbo].[ut_OCVendor] SET RecId = RecId
GO


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_OCVendor')
  DROP PROCEDURE [dbo].[up_Add_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Add_OCVendor] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_OCVendor])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_OCVendor] (RecId) VALUES( @NeueId )
  IF @@ERROR = 0
  BEGIN
    SELECT @NeueId AS RecId
    RETURN
  END
  SELECT 0 AS RecId
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_OCVendor')
  DROP PROCEDURE [dbo].[up_Upd_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Upd_OCVendor]
  @RI integer
 ,@Parm_Ident char(10)
 ,@Parm_Server char(20)
 ,@Parm_DestNr char(15)
 ,@Parm_HostDate datetime
 ,@Parm_Name char(80)
 ,@Parm_Strasse char(40)
 ,@Parm_Plz char(10)
 ,@Parm_Ort char(40)
 ,@Parm_UseKnr tinyint
 ,@Parm_UseUid tinyint
 ,@Parm_UsePwd tinyint
 ,@Parm_Knr char(20)
 ,@Parm_Uid char(40)
 ,@Parm_Pwd char(40)
 ,@Parm_IdsVer char(3)
 ,@Parm_IdsUri char(200)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_OCVendor] SET
     [Ident] = RTRIM(@Parm_Ident)
    ,[Server] = RTRIM(@Parm_Server)
    ,[DestNr] = RTRIM(@Parm_DestNr)
    ,[HostDate] = @Parm_HostDate
    ,[Name] = RTRIM(@Parm_Name)
    ,[Strasse] = RTRIM(@Parm_Strasse)
    ,[Plz] = RTRIM(@Parm_Plz)
    ,[Ort] = RTRIM(@Parm_Ort)
    ,[UseKnr] = @Parm_UseKnr
    ,[UseUid] = @Parm_UseUid
    ,[UsePwd] = @Parm_UsePwd
    ,[Knr] = RTRIM(@Parm_Knr)
    ,[Uid] = RTRIM(@Parm_Uid)
    ,[Pwd] = RTRIM(@Parm_Pwd)
    ,[IdsVer] = RTRIM(@Parm_IdsVer)
    ,[IdsUri] = RTRIM(@Parm_IdsUri)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_OCVendor')
  DROP PROCEDURE [dbo].[up_Sel_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Sel_OCVendor]
  @RI integer
AS
SELECT
     [Ident]
    ,[Server]
    ,[DestNr]
    ,[HostDate]
    ,[Name]
    ,[Strasse]
    ,[Plz]
    ,[Ort]
    ,[UseKnr]
    ,[UseUid]
    ,[UsePwd]
    ,[Knr]
    ,[Uid]
    ,[Pwd]
    ,[IdsVer]
    ,[IdsUri]
  FROM [dbo].[ut_OCVendor]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_OCVendor')
  DROP PROCEDURE [dbo].[up_Del_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Del_OCVendor]
  @RI integer
AS
  DELETE FROM [dbo].[ut_OCVendor] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_OCVendor')
  DROP PROCEDURE [dbo].[up_Reorg_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Reorg_OCVendor]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_OCVendor] ORDER BY RecId
    DECLARE  @CurrId  integer
    DECLARE  @NextId  integer
    --BEGIN TRANSACTION
    OPEN C
    SET @NextId = 1
    FETCH NEXT FROM C INTO @CurrId
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
      IF @CurrId <> @NextId
      UPDATE [dbo].[ut_OCVendor] SET RecId=@NextId WHERE CURRENT OF C
      SET @NextId = @NextId + 1
      FETCH NEXT FROM C INTO @CurrId
    END
    CLOSE C
    --COMMIT TRANSACTION
    DEALLOCATE C
  END

  IF (@bDbcc = 1)
  BEGIN
    DBCC DBREINDEX ( [ut_OCVendor] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_OCVendor')
  DROP PROCEDURE [dbo].[up_Append_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_Append_OCVendor]
  @Parm_Ident char(10)
 ,@Parm_Server char(20)
 ,@Parm_DestNr char(15)
 ,@Parm_HostDate datetime
 ,@Parm_Name char(80)
 ,@Parm_Strasse char(40)
 ,@Parm_Plz char(10)
 ,@Parm_Ort char(40)
 ,@Parm_UseKnr tinyint
 ,@Parm_UseUid tinyint
 ,@Parm_UsePwd tinyint
 ,@Parm_Knr char(20)
 ,@Parm_Uid char(40)
 ,@Parm_Pwd char(40)
 ,@Parm_IdsVer char(3)
 ,@Parm_IdsUri char(200)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_OCVendor])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_OCVendor] (
    RecId
   ,[Ident]
   ,[Server]
   ,[DestNr]
   ,[HostDate]
   ,[Name]
   ,[Strasse]
   ,[Plz]
   ,[Ort]
   ,[UseKnr]
   ,[UseUid]
   ,[UsePwd]
   ,[Knr]
   ,[Uid]
   ,[Pwd]
   ,[IdsVer]
   ,[IdsUri]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_Ident)
   ,RTRIM(@Parm_Server)
   ,RTRIM(@Parm_DestNr)
   ,@Parm_HostDate
   ,RTRIM(@Parm_Name)
   ,RTRIM(@Parm_Strasse)
   ,RTRIM(@Parm_Plz)
   ,RTRIM(@Parm_Ort)
   ,@Parm_UseKnr
   ,@Parm_UseUid
   ,@Parm_UsePwd
   ,RTRIM(@Parm_Knr)
   ,RTRIM(@Parm_Uid)
   ,RTRIM(@Parm_Pwd)
   ,RTRIM(@Parm_IdsVer)
   ,RTRIM(@Parm_IdsUri)
       )
  IF @@ERROR = 0
  BEGIN
    SELECT @NeueId AS RecId
    RETURN
  END
  SELECT 0 AS RecId
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_OCVendor')
  DROP PROCEDURE [dbo].[up_TrSel_OCVendor]
GO
CREATE PROCEDURE [dbo].[up_TrSel_OCVendor]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Ident]))
      +LTRIM(RTRIM([Server]))
      +LTRIM(RTRIM([DestNr]))
      +LTRIM(RTRIM([Name]))
      +LTRIM(RTRIM([Strasse]))
      +LTRIM(RTRIM([Plz]))
      +LTRIM(RTRIM([Ort]))
      +LTRIM(RTRIM([Knr]))
      +LTRIM(RTRIM([Uid]))
      +LTRIM(RTRIM([Pwd]))
      +LTRIM(RTRIM([IdsVer]))
      +LTRIM(RTRIM([IdsUri]))
    AS Data
  FROM     [dbo].[ut_OCVendor]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_OCVendor_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_First_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_Last_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_Prior_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_Next_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_Next50_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_FindL_OCVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OCVendor_Key00')
  DROP PROCEDURE [dbo].[up_FindF_OCVendor_Key00]
GO

CREATE PROCEDURE [dbo].[up_First_OCVendor_Key00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key00_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OCVendor_Key00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key00_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OCVendor_Key00] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key00_Value] > (SELECT [Key00_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_OCVendor_Key00] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key00_Value] < (SELECT [Key00_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_OCVendor_Key00] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key00_Value] > (SELECT [Key00_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_OCVendor_Key00] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key00_Value] < (SELECT [Key00_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_FindF_OCVendor_Key00] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key00_Value] AS Key_Value FROM [dbo].[ut_OCVendor_Keys]
      WHERE [Key00_Value] >= SUBSTRING(@xKey,1,@xLen)
      ORDER BY [Key00_Value]
    ) a
  WHERE a.Key_Value like SUBSTRING(@xKey,1,@xLen)+'%'
GO

CREATE PROCEDURE [dbo].[up_FindL_OCVendor_Key00] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key00_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key00_Value] DESC
GO

CREATE INDEX [Ik_Key01] ON [dbo].[ut_OCVendor_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_First_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_Last_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_Prior_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_Next_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_Next50_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_FindL_OCVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OCVendor_Key01')
  DROP PROCEDURE [dbo].[up_FindF_OCVendor_Key01]
GO

CREATE PROCEDURE [dbo].[up_First_OCVendor_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OCVendor_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key01_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OCVendor_Key01] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key01_Value] > (SELECT [Key01_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_OCVendor_Key01] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key01_Value] < (SELECT [Key01_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_OCVendor_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key01_Value] > (SELECT [Key01_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_OCVendor_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key01_Value] < (SELECT [Key01_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_FindF_OCVendor_Key01] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key01_Value] AS Key_Value FROM [dbo].[ut_OCVendor_Keys]
      WHERE [Key01_Value] >= SUBSTRING(@xKey,1,@xLen)
      ORDER BY [Key01_Value]
    ) a
  WHERE a.Key_Value like SUBSTRING(@xKey,1,@xLen)+'%'
GO

CREATE PROCEDURE [dbo].[up_FindL_OCVendor_Key01] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key01_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key01_Value] DESC
GO

CREATE INDEX [Ik_Key02] ON [dbo].[ut_OCVendor_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_First_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_Last_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_Prior_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_Next_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_Next50_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_FindL_OCVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OCVendor_Key02')
  DROP PROCEDURE [dbo].[up_FindF_OCVendor_Key02]
GO

CREATE PROCEDURE [dbo].[up_First_OCVendor_Key02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key02_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OCVendor_Key02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys] ORDER BY [Key02_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OCVendor_Key02] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key02_Value] > (SELECT [Key02_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_OCVendor_Key02] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key02_Value] < (SELECT [Key02_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_OCVendor_Key02] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key02_Value] > (SELECT [Key02_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_OCVendor_Key02] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key02_Value] < (SELECT [Key02_Value] FROM [dbo].[ut_OCVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_FindF_OCVendor_Key02] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key02_Value] AS Key_Value FROM [dbo].[ut_OCVendor_Keys]
      WHERE [Key02_Value] >= SUBSTRING(@xKey,1,@xLen)
      ORDER BY [Key02_Value]
    ) a
  WHERE a.Key_Value like SUBSTRING(@xKey,1,@xLen)+'%'
GO

CREATE PROCEDURE [dbo].[up_FindL_OCVendor_Key02] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OCVendor_Keys]
  WHERE [Key02_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key02_Value] DESC
GO

