------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_Projektueberwachung')
BEGIN
CREATE TABLE [dbo].[ut_Projektueberwachung]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Nummer] char(8) DEFAULT ' '
  ,[Projekt] char(8) DEFAULT ' '
  ,[Belart] char(2) DEFAULT ' '
  ,[Belnr] char(8) DEFAULT ' '
  ,[Bezeichnung] char(100) DEFAULT ' '
  ,[reserv1] char(10) DEFAULT ' '
  ,[reserv2] char(10) DEFAULT ' '
  ,[reserv3] char(10) DEFAULT ' '
  ,[reserv4] char(10) DEFAULT ' '
  CONSTRAINT [Pk_Projektueberwachung]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Projektueberwachung_KeyDel')
  DROP TRIGGER [dbo].[tr_Projektueberwachung_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Projektueberwachung_KeyUpd')
  DROP TRIGGER [dbo].[tr_Projektueberwachung_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_Projektueberwachung_Keys')
  DROP TABLE [dbo].[ut_Projektueberwachung_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Nummer')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [Nummer] 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_Projektueberwachung' and sc.[name] = 'Projekt')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [Projekt] 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_Projektueberwachung' and sc.[name] = 'Belart')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [Belart] 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_Projektueberwachung' and sc.[name] = 'Belnr')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [Belnr] 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_Projektueberwachung' and sc.[name] = 'Bezeichnung')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [Bezeichnung] char(100) 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_Projektueberwachung' and sc.[name] = 'reserv1')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [reserv1] 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_Projektueberwachung' and sc.[name] = 'reserv2')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [reserv2] 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_Projektueberwachung' and sc.[name] = 'reserv3')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [reserv3] 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_Projektueberwachung' and sc.[name] = 'reserv4')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ADD [reserv4] char(10) NOT NULL DEFAULT ' '
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Nummer')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [Nummer] char(8)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Projekt')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [Projekt] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Belart')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [Belart] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Belnr')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [Belnr] char(8)
END
GO
IF 100 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'Bezeichnung')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [Bezeichnung] char(100)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'reserv1')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [reserv1] char(10)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'reserv2')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [reserv2] char(10)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'reserv3')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [reserv3] char(10)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Projektueberwachung' and sc.[name] = 'reserv4')
BEGIN
  ALTER TABLE [dbo].[ut_Projektueberwachung] ALTER COLUMN [reserv4] char(10)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Projektueberwachung')
  DROP VIEW [dbo].[Projektueberwachung]
GO
CREATE VIEW [dbo].[Projektueberwachung] AS
  SELECT * FROM [dbo].[ut_Projektueberwachung]
GO
CREATE TABLE [dbo].[ut_Projektueberwachung_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key0_Value] CHAR(36) NOT NULL
  ,[Key1_Value] CHAR(28) NOT NULL
  ,[Key2_Value] CHAR(20) NOT NULL
  ,[Key3_Value] CHAR(20) NOT NULL
  ,[Key4_Value] CHAR(20) NOT NULL
  ,[Key5_Value] CHAR(20) NOT NULL
  CONSTRAINT [Pk_ut_Projektueberwachung_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_Projektueberwachung_KeyDel] ON [dbo].[ut_Projektueberwachung]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_Projektueberwachung_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_Projektueberwachung_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key0_Value],[Key1_Value],[Key2_Value],[Key3_Value],[Key4_Value],[Key5_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(8),[Nummer])+convert(char(8),[Projekt])+convert(char(2),[Belart])+convert(char(8),[Belnr])+STR(RecId,10))
     ,UPPER(convert(char(8),[Projekt])+convert(char(2),[Belart])+convert(char(8),[Belnr])+STR(RecId,10))
     ,UPPER(convert(char(2),[Belart])+convert(char(8),[Belnr])+STR(RecId,10))
     ,UPPER(convert(char(8),[Nummer])+convert(char(2),[Belart])+STR(RecId,10))
     ,UPPER(convert(char(2),[Belart])+convert(char(8),[Nummer])+STR(RecId,10))
     ,UPPER(convert(char(2),[Belart])+convert(char(8),[Projekt])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_Projektueberwachung_Keys] WITH (SERIALIZABLE) SET
    [Key0_Value] = UPPER(convert(char(8),[Nummer])+convert(char(8),[Projekt])+convert(char(2),[Belart])+convert(char(8),[Belnr])+STR([RecId],10))
   ,[Key1_Value] = UPPER(convert(char(8),[Projekt])+convert(char(2),[Belart])+convert(char(8),[Belnr])+STR([RecId],10))
   ,[Key2_Value] = UPPER(convert(char(2),[Belart])+convert(char(8),[Belnr])+STR([RecId],10))
   ,[Key3_Value] = UPPER(convert(char(8),[Nummer])+convert(char(2),[Belart])+STR([RecId],10))
   ,[Key4_Value] = UPPER(convert(char(2),[Belart])+convert(char(8),[Nummer])+STR([RecId],10))
   ,[Key5_Value] = UPPER(convert(char(2),[Belart])+convert(char(8),[Projekt])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Add_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Add_Projektueberwachung] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_Projektueberwachung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Projektueberwachung] (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_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Upd_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Upd_Projektueberwachung]
  @RI integer
 ,@Parm_Nummer char(8)
 ,@Parm_Projekt char(8)
 ,@Parm_Belart char(2)
 ,@Parm_Belnr char(8)
 ,@Parm_Bezeichnung char(100)
 ,@Parm_reserv1 char(10)
 ,@Parm_reserv2 char(10)
 ,@Parm_reserv3 char(10)
 ,@Parm_reserv4 char(10)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_Projektueberwachung] SET
     [Nummer] = RTRIM(@Parm_Nummer)
    ,[Projekt] = RTRIM(@Parm_Projekt)
    ,[Belart] = RTRIM(@Parm_Belart)
    ,[Belnr] = RTRIM(@Parm_Belnr)
    ,[Bezeichnung] = RTRIM(@Parm_Bezeichnung)
    ,[reserv1] = RTRIM(@Parm_reserv1)
    ,[reserv2] = RTRIM(@Parm_reserv2)
    ,[reserv3] = RTRIM(@Parm_reserv3)
    ,[reserv4] = RTRIM(@Parm_reserv4)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Sel_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Sel_Projektueberwachung]
  @RI integer
AS
SELECT
     [Nummer]
    ,[Projekt]
    ,[Belart]
    ,[Belnr]
    ,[Bezeichnung]
    ,[reserv1]
    ,[reserv2]
    ,[reserv3]
    ,[reserv4]
  FROM [dbo].[ut_Projektueberwachung]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Del_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Del_Projektueberwachung]
  @RI integer
AS
  DELETE FROM [dbo].[ut_Projektueberwachung] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Reorg_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Reorg_Projektueberwachung]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_Projektueberwachung] 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_Projektueberwachung] 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_Projektueberwachung] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_Append_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_Append_Projektueberwachung]
  @Parm_Nummer char(8)
 ,@Parm_Projekt char(8)
 ,@Parm_Belart char(2)
 ,@Parm_Belnr char(8)
 ,@Parm_Bezeichnung char(100)
 ,@Parm_reserv1 char(10)
 ,@Parm_reserv2 char(10)
 ,@Parm_reserv3 char(10)
 ,@Parm_reserv4 char(10)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_Projektueberwachung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Projektueberwachung] (
    RecId
   ,[Nummer]
   ,[Projekt]
   ,[Belart]
   ,[Belnr]
   ,[Bezeichnung]
   ,[reserv1]
   ,[reserv2]
   ,[reserv3]
   ,[reserv4]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_Nummer)
   ,RTRIM(@Parm_Projekt)
   ,RTRIM(@Parm_Belart)
   ,RTRIM(@Parm_Belnr)
   ,RTRIM(@Parm_Bezeichnung)
   ,RTRIM(@Parm_reserv1)
   ,RTRIM(@Parm_reserv2)
   ,RTRIM(@Parm_reserv3)
   ,RTRIM(@Parm_reserv4)
       )
  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_Projektueberwachung')
  DROP PROCEDURE [dbo].[up_TrSel_Projektueberwachung]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Projektueberwachung]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Nummer]))
      +LTRIM(RTRIM([Projekt]))
      +LTRIM(RTRIM([Belart]))
      +LTRIM(RTRIM([Belnr]))
      +LTRIM(RTRIM([Bezeichnung]))
      +LTRIM(RTRIM([reserv1]))
      +LTRIM(RTRIM([reserv2]))
      +LTRIM(RTRIM([reserv3]))
      +LTRIM(RTRIM([reserv4]))
    AS Data
  FROM     [dbo].[ut_Projektueberwachung]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key0] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key0_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key0')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key0]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key0]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key0_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key0]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key0_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key0] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key0_Value] > (SELECT [Key0_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key0_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key0] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key0_Value] > (SELECT [Key0_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key0_Value]
GO

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

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

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

CREATE INDEX [Ik_Key1] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key1_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key1')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key1]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key1]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key1_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key1]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key1_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key1] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key1_Value] > (SELECT [Key1_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key1_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key1] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key1_Value] > (SELECT [Key1_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key1_Value]
GO

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

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

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

CREATE INDEX [Ik_Key2] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key2_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key2')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key2]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key2]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key2_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key2]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key2_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key2] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key2_Value] > (SELECT [Key2_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key2_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key2] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key2_Value] > (SELECT [Key2_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key2_Value]
GO

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

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

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

CREATE INDEX [Ik_Key3] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key3_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key3')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key3]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key3]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key3_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key3]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key3_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key3] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key3_Value] > (SELECT [Key3_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key3_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key3] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key3_Value] > (SELECT [Key3_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key3_Value]
GO

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

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

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

CREATE INDEX [Ik_Key4] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key4_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key4')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key4]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key4]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key4_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key4]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key4_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key4] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key4_Value] > (SELECT [Key4_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key4_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key4] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key4_Value] > (SELECT [Key4_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key4_Value]
GO

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

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

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

CREATE INDEX [Ik_Key5] ON [dbo].[ut_Projektueberwachung_Keys]
( [Key5_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_First_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_Last_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_Prior_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_Next_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_Prior50_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_FindL_Projektueberwachung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Projektueberwachung_Key5')
  DROP PROCEDURE [dbo].[up_FindF_Projektueberwachung_Key5]
GO

CREATE PROCEDURE [dbo].[up_First_Projektueberwachung_Key5]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key5_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Projektueberwachung_Key5]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys] ORDER BY [Key5_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Projektueberwachung_Key5] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key5_Value] > (SELECT [Key5_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key5_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Projektueberwachung_Key5] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Projektueberwachung_Keys]
  WHERE [Key5_Value] > (SELECT [Key5_Value] FROM [dbo].[ut_Projektueberwachung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key5_Value]
GO

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

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

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

