------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_DnoVendor')
BEGIN
CREATE TABLE [dbo].[ut_DnoVendor]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Ident] char(10) DEFAULT ' '
  ,[DestNr] char(15) DEFAULT ' '
  ,[Match] char(35) DEFAULT ' '
  ,[HostDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Name] char(80) DEFAULT ' '
  ,[Street] char(40) DEFAULT ' '
  ,[Town] char(40) DEFAULT ' '
  ,[Phone] char(40) DEFAULT ' '
  ,[EMail] char(200) DEFAULT ' '
  ,[Internet] char(200) DEFAULT ' '
  ,[bHttpAuth] char(1) DEFAULT ' '
  ,[bCookies] char(1) DEFAULT ' '
  ,[bSSL] char(1) DEFAULT ' '
  ,[bCustNo] char(1) DEFAULT ' '
  ,[bUser] char(1) DEFAULT ' '
  ,[bPassword] char(1) DEFAULT ' '
  ,[bAddition] tinyint DEFAULT 0
  ,[cCustNo] char(40) DEFAULT ' '
  ,[cUserName] char(40) DEFAULT ' '
  ,[cAddition] char(40) DEFAULT ' '
  ,[IdsUrl] char(200) DEFAULT ' '
  CONSTRAINT [Pk_DnoVendor]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_DnoVendor_KeyDel')
  DROP TRIGGER [dbo].[tr_DnoVendor_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_DnoVendor_KeyUpd')
  DROP TRIGGER [dbo].[tr_DnoVendor_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_DnoVendor_Keys')
  DROP TABLE [dbo].[ut_DnoVendor_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Ident')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] 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_DnoVendor' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] 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_DnoVendor' and sc.[name] = 'Match')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [Match] char(35) 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_DnoVendor' and sc.[name] = 'HostDate')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] 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_DnoVendor' and sc.[name] = 'Name')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] 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_DnoVendor' and sc.[name] = 'Street')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [Street] 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_DnoVendor' and sc.[name] = 'Town')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [Town] 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_DnoVendor' and sc.[name] = 'Phone')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [Phone] 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_DnoVendor' and sc.[name] = 'EMail')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [EMail] char(200) 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_DnoVendor' and sc.[name] = 'Internet')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [Internet] char(200) 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_DnoVendor' and sc.[name] = 'bHttpAuth')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bHttpAuth] char(1) 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_DnoVendor' and sc.[name] = 'bCookies')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bCookies] char(1) 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_DnoVendor' and sc.[name] = 'bSSL')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bSSL] char(1) 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_DnoVendor' and sc.[name] = 'bCustNo')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bCustNo] char(1) 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_DnoVendor' and sc.[name] = 'bUser')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bUser] char(1) 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_DnoVendor' and sc.[name] = 'bPassword')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bPassword] char(1) 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_DnoVendor' and sc.[name] = 'bAddition')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [bAddition] 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_DnoVendor' and sc.[name] = 'cCustNo')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [cCustNo] 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_DnoVendor' and sc.[name] = 'cUserName')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [cUserName] 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_DnoVendor' and sc.[name] = 'cAddition')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [cAddition] 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_DnoVendor' and sc.[name] = 'IdsUrl')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ADD [IdsUrl] 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_DnoVendor' and sc.[name] = 'Ident')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Ident] char(10)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [DestNr] char(15)
END
GO
IF 35 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Match')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Match] char(35)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Name')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] 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_DnoVendor' and sc.[name] = 'Street')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Street] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Town')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Town] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Phone')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Phone] char(40)
END
GO
IF 200 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'EMail')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [EMail] char(200)
END
GO
IF 200 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'Internet')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [Internet] char(200)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bHttpAuth')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bHttpAuth] char(1)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bCookies')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bCookies] char(1)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bSSL')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bSSL] char(1)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bCustNo')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bCustNo] char(1)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bUser')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bUser] char(1)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'bPassword')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [bPassword] char(1)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'cCustNo')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [cCustNo] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'cUserName')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [cUserName] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'cAddition')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [cAddition] char(40)
END
GO
IF 200 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DnoVendor' and sc.[name] = 'IdsUrl')
BEGIN
  ALTER TABLE [dbo].[ut_DnoVendor] ALTER COLUMN [IdsUrl] char(200)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'DnoVendor')
  DROP VIEW [dbo].[DnoVendor]
GO
CREATE VIEW [dbo].[DnoVendor] AS
  SELECT * FROM [dbo].[ut_DnoVendor]
GO
CREATE TABLE [dbo].[ut_DnoVendor_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(20) NOT NULL
  ,[Key01_Value] CHAR(25) NOT NULL
  ,[Key02_Value] CHAR(45) NOT NULL
  ,[Key03_Filter] TINYINT NOT NULL
  ,[Key03_Value] CHAR(45) NOT NULL
  CONSTRAINT [Pk_ut_DnoVendor_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_DnoVendor_KeyDel] ON [dbo].[ut_DnoVendor]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_DnoVendor_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_DnoVendor_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Filter],[Key03_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(10),[Ident])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+STR(RecId,10))
     ,UPPER(convert(char(35),[Match])+STR(RecId,10))
     ,CASE WHEN  DestNr <> '' THEN 1 ELSE 0 END
     ,UPPER(convert(char(35),[Match])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_DnoVendor_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(35),[Match])+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(35),[Match])+STR([RecId],10))
   ,[Key03_Filter] = CASE WHEN  DestNr <> '' THEN 1 ELSE 0 END
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_DnoVendor')
  DROP PROCEDURE [dbo].[up_Add_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Add_DnoVendor] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_DnoVendor])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_DnoVendor] (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_DnoVendor')
  DROP PROCEDURE [dbo].[up_Upd_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Upd_DnoVendor]
  @RI integer
 ,@Parm_Ident char(10)
 ,@Parm_DestNr char(15)
 ,@Parm_Match char(35)
 ,@Parm_HostDate datetime
 ,@Parm_Name char(80)
 ,@Parm_Street char(40)
 ,@Parm_Town char(40)
 ,@Parm_Phone char(40)
 ,@Parm_EMail char(200)
 ,@Parm_Internet char(200)
 ,@Parm_bHttpAuth char(1)
 ,@Parm_bCookies char(1)
 ,@Parm_bSSL char(1)
 ,@Parm_bCustNo char(1)
 ,@Parm_bUser char(1)
 ,@Parm_bPassword char(1)
 ,@Parm_bAddition tinyint
 ,@Parm_cCustNo char(40)
 ,@Parm_cUserName char(40)
 ,@Parm_cAddition char(40)
 ,@Parm_IdsUrl char(200)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_DnoVendor] SET
     [Ident] = RTRIM(@Parm_Ident)
    ,[DestNr] = RTRIM(@Parm_DestNr)
    ,[Match] = RTRIM(@Parm_Match)
    ,[HostDate] = @Parm_HostDate
    ,[Name] = RTRIM(@Parm_Name)
    ,[Street] = RTRIM(@Parm_Street)
    ,[Town] = RTRIM(@Parm_Town)
    ,[Phone] = RTRIM(@Parm_Phone)
    ,[EMail] = RTRIM(@Parm_EMail)
    ,[Internet] = RTRIM(@Parm_Internet)
    ,[bHttpAuth] = RTRIM(@Parm_bHttpAuth)
    ,[bCookies] = RTRIM(@Parm_bCookies)
    ,[bSSL] = RTRIM(@Parm_bSSL)
    ,[bCustNo] = RTRIM(@Parm_bCustNo)
    ,[bUser] = RTRIM(@Parm_bUser)
    ,[bPassword] = RTRIM(@Parm_bPassword)
    ,[bAddition] = @Parm_bAddition
    ,[cCustNo] = RTRIM(@Parm_cCustNo)
    ,[cUserName] = RTRIM(@Parm_cUserName)
    ,[cAddition] = RTRIM(@Parm_cAddition)
    ,[IdsUrl] = RTRIM(@Parm_IdsUrl)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_DnoVendor')
  DROP PROCEDURE [dbo].[up_Sel_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Sel_DnoVendor]
  @RI integer
AS
SELECT
     [Ident]
    ,[DestNr]
    ,[Match]
    ,[HostDate]
    ,[Name]
    ,[Street]
    ,[Town]
    ,[Phone]
    ,[EMail]
    ,[Internet]
    ,[bHttpAuth]
    ,[bCookies]
    ,[bSSL]
    ,[bCustNo]
    ,[bUser]
    ,[bPassword]
    ,[bAddition]
    ,[cCustNo]
    ,[cUserName]
    ,[cAddition]
    ,[IdsUrl]
  FROM [dbo].[ut_DnoVendor]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_DnoVendor')
  DROP PROCEDURE [dbo].[up_Del_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Del_DnoVendor]
  @RI integer
AS
  DELETE FROM [dbo].[ut_DnoVendor] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_DnoVendor')
  DROP PROCEDURE [dbo].[up_Reorg_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Reorg_DnoVendor]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_DnoVendor] 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_DnoVendor] 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_DnoVendor] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_DnoVendor')
  DROP PROCEDURE [dbo].[up_Append_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_Append_DnoVendor]
  @Parm_Ident char(10)
 ,@Parm_DestNr char(15)
 ,@Parm_Match char(35)
 ,@Parm_HostDate datetime
 ,@Parm_Name char(80)
 ,@Parm_Street char(40)
 ,@Parm_Town char(40)
 ,@Parm_Phone char(40)
 ,@Parm_EMail char(200)
 ,@Parm_Internet char(200)
 ,@Parm_bHttpAuth char(1)
 ,@Parm_bCookies char(1)
 ,@Parm_bSSL char(1)
 ,@Parm_bCustNo char(1)
 ,@Parm_bUser char(1)
 ,@Parm_bPassword char(1)
 ,@Parm_bAddition tinyint
 ,@Parm_cCustNo char(40)
 ,@Parm_cUserName char(40)
 ,@Parm_cAddition char(40)
 ,@Parm_IdsUrl char(200)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_DnoVendor])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_DnoVendor] (
    RecId
   ,[Ident]
   ,[DestNr]
   ,[Match]
   ,[HostDate]
   ,[Name]
   ,[Street]
   ,[Town]
   ,[Phone]
   ,[EMail]
   ,[Internet]
   ,[bHttpAuth]
   ,[bCookies]
   ,[bSSL]
   ,[bCustNo]
   ,[bUser]
   ,[bPassword]
   ,[bAddition]
   ,[cCustNo]
   ,[cUserName]
   ,[cAddition]
   ,[IdsUrl]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_Ident)
   ,RTRIM(@Parm_DestNr)
   ,RTRIM(@Parm_Match)
   ,@Parm_HostDate
   ,RTRIM(@Parm_Name)
   ,RTRIM(@Parm_Street)
   ,RTRIM(@Parm_Town)
   ,RTRIM(@Parm_Phone)
   ,RTRIM(@Parm_EMail)
   ,RTRIM(@Parm_Internet)
   ,RTRIM(@Parm_bHttpAuth)
   ,RTRIM(@Parm_bCookies)
   ,RTRIM(@Parm_bSSL)
   ,RTRIM(@Parm_bCustNo)
   ,RTRIM(@Parm_bUser)
   ,RTRIM(@Parm_bPassword)
   ,@Parm_bAddition
   ,RTRIM(@Parm_cCustNo)
   ,RTRIM(@Parm_cUserName)
   ,RTRIM(@Parm_cAddition)
   ,RTRIM(@Parm_IdsUrl)
       )
  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_DnoVendor')
  DROP PROCEDURE [dbo].[up_TrSel_DnoVendor]
GO
CREATE PROCEDURE [dbo].[up_TrSel_DnoVendor]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Ident]))
      +LTRIM(RTRIM([DestNr]))
      +LTRIM(RTRIM([Match]))
      +LTRIM(RTRIM([Name]))
      +LTRIM(RTRIM([Street]))
      +LTRIM(RTRIM([Town]))
      +LTRIM(RTRIM([Phone]))
      +LTRIM(RTRIM([EMail]))
      +LTRIM(RTRIM([Internet]))
      +LTRIM(RTRIM([bHttpAuth]))
      +LTRIM(RTRIM([bCookies]))
      +LTRIM(RTRIM([bSSL]))
      +LTRIM(RTRIM([bCustNo]))
      +LTRIM(RTRIM([bUser]))
      +LTRIM(RTRIM([bPassword]))
      +LTRIM(RTRIM([cCustNo]))
      +LTRIM(RTRIM([cUserName]))
      +LTRIM(RTRIM([cAddition]))
      +LTRIM(RTRIM([IdsUrl]))
    AS Data
  FROM     [dbo].[ut_DnoVendor]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_DnoVendor_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_First_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_Last_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_Prior_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_Next_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_Next50_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_FindL_DnoVendor_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DnoVendor_Key00')
  DROP PROCEDURE [dbo].[up_FindF_DnoVendor_Key00]
GO

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

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

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

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

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

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

CREATE PROCEDURE [dbo].[up_FindF_DnoVendor_Key00] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key00_Value] AS Key_Value FROM [dbo].[ut_DnoVendor_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_DnoVendor_Key00] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key00_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key00_Value] DESC
GO

CREATE INDEX [Ik_Key01] ON [dbo].[ut_DnoVendor_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_First_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_Last_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_Prior_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_Next_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_Next50_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_FindL_DnoVendor_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DnoVendor_Key01')
  DROP PROCEDURE [dbo].[up_FindF_DnoVendor_Key01]
GO

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

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

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

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

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

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

CREATE PROCEDURE [dbo].[up_FindF_DnoVendor_Key01] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key01_Value] AS Key_Value FROM [dbo].[ut_DnoVendor_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_DnoVendor_Key01] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key01_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key01_Value] DESC
GO

CREATE INDEX [Ik_Key02] ON [dbo].[ut_DnoVendor_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_First_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_Last_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_Prior_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_Next_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_Next50_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_FindL_DnoVendor_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DnoVendor_Key02')
  DROP PROCEDURE [dbo].[up_FindF_DnoVendor_Key02]
GO

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

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

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

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

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

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

CREATE PROCEDURE [dbo].[up_FindF_DnoVendor_Key02] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key02_Value] AS Key_Value FROM [dbo].[ut_DnoVendor_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_DnoVendor_Key02] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key02_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key02_Value] DESC
GO

CREATE INDEX [Ik_Key03] ON [dbo].[ut_DnoVendor_Keys]
( [Key03_Filter],[Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_First_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_Last_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_Prior_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_Next_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_Next50_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_FindL_DnoVendor_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DnoVendor_Key03')
  DROP PROCEDURE [dbo].[up_FindF_DnoVendor_Key03]
GO

CREATE PROCEDURE [dbo].[up_First_DnoVendor_Key03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 ORDER BY [Key03_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_DnoVendor_Key03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 ORDER BY [Key03_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_DnoVendor_Key03] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 AND [Key03_Value] > (SELECT [Key03_Value] FROM [dbo].[ut_DnoVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key03_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_DnoVendor_Key03] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 AND [Key03_Value] < (SELECT [Key03_Value] FROM [dbo].[ut_DnoVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key03_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_DnoVendor_Key03] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 AND [Key03_Value] > (SELECT [Key03_Value] FROM [dbo].[ut_DnoVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key03_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_DnoVendor_Key03] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 AND [Key03_Value] < (SELECT [Key03_Value] FROM [dbo].[ut_DnoVendor_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key03_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_DnoVendor_Key03] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DnoVendor_Keys]
  WHERE [Key03_Filter] = 1 AND [Key03_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key03_Value] DESC
GO

