------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_OLE_Dokumente')
BEGIN
CREATE TABLE [dbo].[ut_OLE_Dokumente]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[IDENT] char(15) DEFAULT ' '
  ,[DestNr] char(15) DEFAULT ' '
  ,[ProjektNr] char(8) DEFAULT ' '
  ,[BelegArt] char(2) DEFAULT ' '
  ,[BelegNr] char(8) DEFAULT ' '
  ,[DocName] char(255) DEFAULT ' '
  ,[Descrip] char(255) DEFAULT ' '
  ,[DocTyp] char(2) DEFAULT ' '
  ,[DatumAn] char(10) DEFAULT ' '
  ,[AnlageVon] char(15) DEFAULT ' '
  ,[LEditDat] char(10) DEFAULT ' '
  ,[LEditTime] char(8) DEFAULT ' '
  ,[LEditVon] char(15) DEFAULT ' '
  ,[MatchCode] char(15) DEFAULT ' '
  CONSTRAINT [Pk_OLE_Dokumente]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_OLE_Dokumente_KeyDel')
  DROP TRIGGER [dbo].[tr_OLE_Dokumente_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_OLE_Dokumente_KeyUpd')
  DROP TRIGGER [dbo].[tr_OLE_Dokumente_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_OLE_Dokumente_Keys')
  DROP TABLE [dbo].[ut_OLE_Dokumente_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'IDENT')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [IDENT] 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_OLE_Dokumente' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] 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_OLE_Dokumente' and sc.[name] = 'ProjektNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [ProjektNr] char(8) 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_OLE_Dokumente' and sc.[name] = 'BelegArt')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [BelegArt] char(2) 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_OLE_Dokumente' and sc.[name] = 'BelegNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [BelegNr] char(8) 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_OLE_Dokumente' and sc.[name] = 'DocName')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [DocName] char(255) 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_OLE_Dokumente' and sc.[name] = 'Descrip')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [Descrip] char(255) 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_OLE_Dokumente' and sc.[name] = 'DocTyp')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [DocTyp] char(2) 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_OLE_Dokumente' and sc.[name] = 'DatumAn')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [DatumAn] 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_OLE_Dokumente' and sc.[name] = 'AnlageVon')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [AnlageVon] 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_OLE_Dokumente' and sc.[name] = 'LEditDat')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [LEditDat] 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_OLE_Dokumente' and sc.[name] = 'LEditTime')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [LEditTime] char(8) 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_OLE_Dokumente' and sc.[name] = 'LEditVon')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [LEditVon] 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_OLE_Dokumente' and sc.[name] = 'MatchCode')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ADD [MatchCode] char(15) NOT NULL DEFAULT ' '
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'IDENT')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [IDENT] char(15)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'DestNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [DestNr] char(15)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'ProjektNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [ProjektNr] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'BelegArt')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [BelegArt] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'BelegNr')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [BelegNr] char(8)
END
GO
IF 255 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'DocName')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [DocName] char(255)
END
GO
IF 255 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'Descrip')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [Descrip] char(255)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'DocTyp')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [DocTyp] char(2)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'DatumAn')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [DatumAn] char(10)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'AnlageVon')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [AnlageVon] char(15)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'LEditDat')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [LEditDat] char(10)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'LEditTime')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [LEditTime] char(8)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'LEditVon')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [LEditVon] char(15)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_OLE_Dokumente' and sc.[name] = 'MatchCode')
BEGIN
  ALTER TABLE [dbo].[ut_OLE_Dokumente] ALTER COLUMN [MatchCode] char(15)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'OLE_Dokumente')
  DROP VIEW [dbo].[OLE_Dokumente]
GO
CREATE VIEW [dbo].[OLE_Dokumente] AS
  SELECT * FROM [dbo].[ut_OLE_Dokumente]
GO
CREATE TABLE [dbo].[ut_OLE_Dokumente_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(25) NOT NULL
  ,[Key01_Value] CHAR(27) NOT NULL
  ,[Key02_Value] CHAR(35) NOT NULL
  ,[Key03_Value] CHAR(43) NOT NULL
  ,[Key04_Value] CHAR(28) NOT NULL
  ,[Key05_Value] CHAR(25) NOT NULL
  ,[Key06_Value] CHAR(40) NOT NULL
  ,[Key07_Value] CHAR(33) NOT NULL
  ,[Key08_Value] CHAR(50) NOT NULL
  CONSTRAINT [Pk_ut_OLE_Dokumente_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_OLE_Dokumente_KeyDel] ON [dbo].[ut_OLE_Dokumente]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_OLE_Dokumente_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_OLE_Dokumente_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value],[Key06_Value],[Key07_Value],[Key08_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(15),[IDENT])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+convert(char(2),[DocTyp])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+convert(char(10),[DatumAn])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+convert(char(10),[LEditDat])+convert(char(8),[LEditTime])+STR(RecId,10))
     ,UPPER(convert(char(8),[ProjektNr])+convert(char(10),[DatumAn])+STR(RecId,10))
     ,UPPER(convert(char(15),[MatchCode])+STR(RecId,10))
     ,UPPER(convert(char(15),[DestNr])+convert(char(15),[IDENT])+STR(RecId,10))
     ,UPPER(convert(char(8),[ProjektNr])+convert(char(15),[IDENT])+STR(RecId,10))
     ,UPPER(convert(char(2),[DocTyp])+convert(char(8),[ProjektNr])+convert(char(15),[DestNr])+convert(char(15),[IDENT])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_OLE_Dokumente_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(15),[IDENT])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(15),[DestNr])+convert(char(2),[DocTyp])+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(15),[DestNr])+convert(char(10),[DatumAn])+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(15),[DestNr])+convert(char(10),[LEditDat])+convert(char(8),[LEditTime])+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(8),[ProjektNr])+convert(char(10),[DatumAn])+STR([RecId],10))
   ,[Key05_Value] = UPPER(convert(char(15),[MatchCode])+STR([RecId],10))
   ,[Key06_Value] = UPPER(convert(char(15),[DestNr])+convert(char(15),[IDENT])+STR([RecId],10))
   ,[Key07_Value] = UPPER(convert(char(8),[ProjektNr])+convert(char(15),[IDENT])+STR([RecId],10))
   ,[Key08_Value] = UPPER(convert(char(2),[DocTyp])+convert(char(8),[ProjektNr])+convert(char(15),[DestNr])+convert(char(15),[IDENT])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Add_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Add_OLE_Dokumente] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_OLE_Dokumente])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_OLE_Dokumente] (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_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Upd_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Upd_OLE_Dokumente]
  @RI integer
 ,@Parm_IDENT char(15)
 ,@Parm_DestNr char(15)
 ,@Parm_ProjektNr char(8)
 ,@Parm_BelegArt char(2)
 ,@Parm_BelegNr char(8)
 ,@Parm_DocName char(255)
 ,@Parm_Descrip char(255)
 ,@Parm_DocTyp char(2)
 ,@Parm_DatumAn char(10)
 ,@Parm_AnlageVon char(15)
 ,@Parm_LEditDat char(10)
 ,@Parm_LEditTime char(8)
 ,@Parm_LEditVon char(15)
 ,@Parm_MatchCode char(15)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_OLE_Dokumente] SET
     [IDENT] = RTRIM(@Parm_IDENT)
    ,[DestNr] = RTRIM(@Parm_DestNr)
    ,[ProjektNr] = RTRIM(@Parm_ProjektNr)
    ,[BelegArt] = RTRIM(@Parm_BelegArt)
    ,[BelegNr] = RTRIM(@Parm_BelegNr)
    ,[DocName] = RTRIM(@Parm_DocName)
    ,[Descrip] = RTRIM(@Parm_Descrip)
    ,[DocTyp] = RTRIM(@Parm_DocTyp)
    ,[DatumAn] = RTRIM(@Parm_DatumAn)
    ,[AnlageVon] = RTRIM(@Parm_AnlageVon)
    ,[LEditDat] = RTRIM(@Parm_LEditDat)
    ,[LEditTime] = RTRIM(@Parm_LEditTime)
    ,[LEditVon] = RTRIM(@Parm_LEditVon)
    ,[MatchCode] = RTRIM(@Parm_MatchCode)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Sel_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Sel_OLE_Dokumente]
  @RI integer
AS
SELECT
     [IDENT]
    ,[DestNr]
    ,[ProjektNr]
    ,[BelegArt]
    ,[BelegNr]
    ,[DocName]
    ,[Descrip]
    ,[DocTyp]
    ,[DatumAn]
    ,[AnlageVon]
    ,[LEditDat]
    ,[LEditTime]
    ,[LEditVon]
    ,[MatchCode]
  FROM [dbo].[ut_OLE_Dokumente]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Del_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Del_OLE_Dokumente]
  @RI integer
AS
  DELETE FROM [dbo].[ut_OLE_Dokumente] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Reorg_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Reorg_OLE_Dokumente]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_OLE_Dokumente] 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_OLE_Dokumente] 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_OLE_Dokumente] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_Append_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_Append_OLE_Dokumente]
  @Parm_IDENT char(15)
 ,@Parm_DestNr char(15)
 ,@Parm_ProjektNr char(8)
 ,@Parm_BelegArt char(2)
 ,@Parm_BelegNr char(8)
 ,@Parm_DocName char(255)
 ,@Parm_Descrip char(255)
 ,@Parm_DocTyp char(2)
 ,@Parm_DatumAn char(10)
 ,@Parm_AnlageVon char(15)
 ,@Parm_LEditDat char(10)
 ,@Parm_LEditTime char(8)
 ,@Parm_LEditVon char(15)
 ,@Parm_MatchCode char(15)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_OLE_Dokumente])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_OLE_Dokumente] (
    RecId
   ,[IDENT]
   ,[DestNr]
   ,[ProjektNr]
   ,[BelegArt]
   ,[BelegNr]
   ,[DocName]
   ,[Descrip]
   ,[DocTyp]
   ,[DatumAn]
   ,[AnlageVon]
   ,[LEditDat]
   ,[LEditTime]
   ,[LEditVon]
   ,[MatchCode]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_IDENT)
   ,RTRIM(@Parm_DestNr)
   ,RTRIM(@Parm_ProjektNr)
   ,RTRIM(@Parm_BelegArt)
   ,RTRIM(@Parm_BelegNr)
   ,RTRIM(@Parm_DocName)
   ,RTRIM(@Parm_Descrip)
   ,RTRIM(@Parm_DocTyp)
   ,RTRIM(@Parm_DatumAn)
   ,RTRIM(@Parm_AnlageVon)
   ,RTRIM(@Parm_LEditDat)
   ,RTRIM(@Parm_LEditTime)
   ,RTRIM(@Parm_LEditVon)
   ,RTRIM(@Parm_MatchCode)
       )
  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_OLE_Dokumente')
  DROP PROCEDURE [dbo].[up_TrSel_OLE_Dokumente]
GO
CREATE PROCEDURE [dbo].[up_TrSel_OLE_Dokumente]
AS
  SELECT   RecId,
      LTRIM(RTRIM([IDENT]))
      +LTRIM(RTRIM([DestNr]))
      +LTRIM(RTRIM([ProjektNr]))
      +LTRIM(RTRIM([BelegArt]))
      +LTRIM(RTRIM([BelegNr]))
      +LTRIM(RTRIM([DocName]))
      +LTRIM(RTRIM([Descrip]))
      +LTRIM(RTRIM([DocTyp]))
      +LTRIM(RTRIM([DatumAn]))
      +LTRIM(RTRIM([AnlageVon]))
      +LTRIM(RTRIM([LEditDat]))
      +LTRIM(RTRIM([LEditTime]))
      +LTRIM(RTRIM([LEditVon]))
      +LTRIM(RTRIM([MatchCode]))
    AS Data
  FROM     [dbo].[ut_OLE_Dokumente]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key00')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key01')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key02')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key03')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key03]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key03_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key03_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key03] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key03_Value] > (SELECT [Key03_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key03_Value]
GO

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key04')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key04]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key04_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key04_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key04] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key04_Value] > (SELECT [Key04_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key04] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key04_Value] > (SELECT [Key04_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value]
GO

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

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key05')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key05]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key05_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key05_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key05] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key05_Value] > (SELECT [Key05_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key05] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key05_Value] > (SELECT [Key05_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value]
GO

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

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

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

CREATE INDEX [Ik_Key06] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key06_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key06')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key06]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key06_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key06_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key06] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key06] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

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

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

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

CREATE INDEX [Ik_Key07] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key07_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key07')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key07]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key07_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key07_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key07] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key07] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

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

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

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

CREATE INDEX [Ik_Key08] ON [dbo].[ut_OLE_Dokumente_Keys]
( [Key08_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_First_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_Prior_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_Prior50_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_FindL_OLE_Dokumente_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_OLE_Dokumente_Key08')
  DROP PROCEDURE [dbo].[up_FindF_OLE_Dokumente_Key08]
GO

CREATE PROCEDURE [dbo].[up_First_OLE_Dokumente_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key08_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_OLE_Dokumente_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys] ORDER BY [Key08_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_OLE_Dokumente_Key08] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_OLE_Dokumente_Key08] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_OLE_Dokumente_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_OLE_Dokumente_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

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

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

