------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_Zeiterfassung')
BEGIN
CREATE TABLE [dbo].[ut_Zeiterfassung]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[arbtnr] char(4) DEFAULT ' '
  ,[art] char(2) DEFAULT ' '
  ,[belegnr] char(8) DEFAULT ' '
  ,[posnr] char(20) DEFAULT ' '
  ,[lohnart] char(3) DEFAULT ' '
  ,[tag] char(2) DEFAULT ' '
  ,[monat] char(2) DEFAULT ' '
  ,[jahr] char(4) DEFAULT ' '
  ,[kstnr] char(20) DEFAULT ' '
  ,[stunden] float DEFAULT 0
  ,[betrag] float DEFAULT 0
  ,[bsgru] char(2) DEFAULT ' '
  ,[prsatz] float DEFAULT 0
  ,[satzstrzei] char(1) DEFAULT ' '
  ,[wkz] char(10) DEFAULT ' '
  ,[eurokurs] float DEFAULT 0
  ,[eklohn] float DEFAULT 0
  ,[bruttolohn] float DEFAULT 0
  ,[bemerkung] char(50) DEFAULT ' '
  ,[PrjNr] char(8) DEFAULT ' '
  ,[ExpTPO] tinyint DEFAULT 0
  ,[ExpConnect] tinyint DEFAULT 0
  ,[ExpTopLohn] tinyint DEFAULT 0
  ,[ExpSPLohn] tinyint DEFAULT 0
  ,[ExpFibu] integer DEFAULT 0
  CONSTRAINT [Pk_Zeiterfassung]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Zeiterfassung_KeyDel')
  DROP TRIGGER [dbo].[tr_Zeiterfassung_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Zeiterfassung_KeyUpd')
  DROP TRIGGER [dbo].[tr_Zeiterfassung_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_Zeiterfassung_Keys')
  DROP TABLE [dbo].[ut_Zeiterfassung_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'arbtnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [arbtnr] char(4) 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_Zeiterfassung' and sc.[name] = 'art')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [art] 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_Zeiterfassung' and sc.[name] = 'belegnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] 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_Zeiterfassung' and sc.[name] = 'posnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [posnr] char(20) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'lohnart')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [lohnart] char(3) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'tag')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [tag] 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_Zeiterfassung' and sc.[name] = 'monat')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [monat] 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_Zeiterfassung' and sc.[name] = 'jahr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [jahr] char(4) 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_Zeiterfassung' and sc.[name] = 'kstnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [kstnr] char(20) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'stunden')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [stunden] float 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_Zeiterfassung' and sc.[name] = 'betrag')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [betrag] float 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_Zeiterfassung' and sc.[name] = 'bsgru')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [bsgru] 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_Zeiterfassung' and sc.[name] = 'prsatz')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [prsatz] float 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_Zeiterfassung' and sc.[name] = 'satzstrzei')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [satzstrzei] 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_Zeiterfassung' and sc.[name] = 'wkz')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [wkz] 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_Zeiterfassung' and sc.[name] = 'eurokurs')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [eurokurs] float 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_Zeiterfassung' and sc.[name] = 'eklohn')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [eklohn] float 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_Zeiterfassung' and sc.[name] = 'bruttolohn')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [bruttolohn] float 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_Zeiterfassung' and sc.[name] = 'bemerkung')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [bemerkung] char(50) 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_Zeiterfassung' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [PrjNr] 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_Zeiterfassung' and sc.[name] = 'ExpTPO')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [ExpTPO] 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_Zeiterfassung' and sc.[name] = 'ExpConnect')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [ExpConnect] 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_Zeiterfassung' and sc.[name] = 'ExpTopLohn')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [ExpTopLohn] 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_Zeiterfassung' and sc.[name] = 'ExpSPLohn')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [ExpSPLohn] 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_Zeiterfassung' and sc.[name] = 'ExpFibu')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ADD [ExpFibu] integer NOT NULL DEFAULT 0
END
GO
IF 4 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'arbtnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [arbtnr] char(4)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'art')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [art] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'belegnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [belegnr] char(8)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'posnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [posnr] char(20)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'lohnart')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [lohnart] char(3)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'tag')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [tag] char(2)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'monat')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [monat] char(2)
END
GO
IF 4 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'jahr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [jahr] char(4)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'kstnr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [kstnr] char(20)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'bsgru')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [bsgru] char(2)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'satzstrzei')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [satzstrzei] char(1)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'wkz')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [wkz] char(10)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'bemerkung')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [bemerkung] char(50)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Zeiterfassung' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_Zeiterfassung] ALTER COLUMN [PrjNr] char(8)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Zeiterfassung')
  DROP VIEW [dbo].[Zeiterfassung]
GO
CREATE VIEW [dbo].[Zeiterfassung] AS
  SELECT * FROM [dbo].[ut_Zeiterfassung]
GO
CREATE TABLE [dbo].[ut_Zeiterfassung_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key0_Value] CHAR(55) NOT NULL
  ,[Key1_Value] CHAR(55) NOT NULL
  ,[Key2_Value] CHAR(55) NOT NULL
  ,[Key3_Value] CHAR(55) NOT NULL
  ,[Key4_Value] CHAR(55) NOT NULL
  ,[Key5_Value] CHAR(55) NOT NULL
  ,[Key6_Value] CHAR(55) NOT NULL
  ,[Key7_Value] CHAR(26) NOT NULL
  ,[Key8_Value] CHAR(55) NOT NULL
  ,[Key9_Value] CHAR(35) NOT NULL
  ,[KeyA_Value] CHAR(35) NOT NULL
  ,[KeyB_Value] CHAR(35) NOT NULL
  CONSTRAINT [Pk_ut_Zeiterfassung_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_Zeiterfassung_KeyDel] ON [dbo].[ut_Zeiterfassung]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_Zeiterfassung_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_Zeiterfassung_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key0_Value],[Key1_Value],[Key2_Value],[Key3_Value],[Key4_Value],[Key5_Value],[Key6_Value],[Key7_Value],[Key8_Value],[Key9_Value],[KeyA_Value],[KeyB_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+convert(char(2),[tag])+STR(RecId,10))
     ,UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+convert(char(2),[tag])+STR(RecId,10))
     ,UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+STR(RecId,10))
     ,UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+STR(RecId,10))
     ,UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(3),[lohnart])+convert(char(4),[arbtnr])+convert(char(2),[tag])+STR(RecId,10))
     ,UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(3),[lohnart])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(2),[tag])+STR(RecId,10))
     ,UPPER(convert(char(4),[arbtnr])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(3),[lohnart])+STR(RecId,10))
     ,UPPER(STR([ExpFibu],1,0)+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(4),[arbtnr])+convert(char(2),[tag])+convert(char(3),[lohnart])+STR(RecId,10))
     ,UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+STR(RecId,10))
     ,UPPER(convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(2),[art])+convert(char(8),[belegnr])+STR(RecId,10))
     ,UPPER(convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(4),[arbtnr])+STR(RecId,10))
     ,UPPER(convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+convert(char(2),[art])+convert(char(8),[belegnr])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_Zeiterfassung_Keys] WITH (SERIALIZABLE) SET
    [Key0_Value] = UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+convert(char(2),[tag])+STR([RecId],10))
   ,[Key1_Value] = UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+convert(char(2),[tag])+STR([RecId],10))
   ,[Key2_Value] = UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+STR([RecId],10))
   ,[Key3_Value] = UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+STR([RecId],10))
   ,[Key4_Value] = UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(3),[lohnart])+convert(char(4),[arbtnr])+convert(char(2),[tag])+STR([RecId],10))
   ,[Key5_Value] = UPPER(convert(char(4),[arbtnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(3),[lohnart])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(2),[tag])+STR([RecId],10))
   ,[Key6_Value] = UPPER(convert(char(4),[arbtnr])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(3),[lohnart])+STR([RecId],10))
   ,[Key7_Value] = UPPER(STR([ExpFibu],1,0)+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(4),[arbtnr])+convert(char(2),[tag])+convert(char(3),[lohnart])+STR([RecId],10))
   ,[Key8_Value] = UPPER(convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(20),[posnr])+convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+STR([RecId],10))
   ,[Key9_Value] = UPPER(convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(2),[art])+convert(char(8),[belegnr])+STR([RecId],10))
   ,[KeyA_Value] = UPPER(convert(char(3),[lohnart])+convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(2),[art])+convert(char(8),[belegnr])+convert(char(4),[arbtnr])+STR([RecId],10))
   ,[KeyB_Value] = UPPER(convert(char(4),[jahr])+convert(char(2),[monat])+convert(char(2),[tag])+convert(char(4),[arbtnr])+convert(char(3),[lohnart])+convert(char(2),[art])+convert(char(8),[belegnr])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Add_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Add_Zeiterfassung] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_Zeiterfassung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Zeiterfassung] (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_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Upd_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Upd_Zeiterfassung]
  @RI integer
 ,@Parm_arbtnr char(4)
 ,@Parm_art char(2)
 ,@Parm_belegnr char(8)
 ,@Parm_posnr char(20)
 ,@Parm_lohnart char(3)
 ,@Parm_tag char(2)
 ,@Parm_monat char(2)
 ,@Parm_jahr char(4)
 ,@Parm_kstnr char(20)
 ,@Parm_stunden float
 ,@Parm_betrag float
 ,@Parm_bsgru char(2)
 ,@Parm_prsatz float
 ,@Parm_satzstrzei char(1)
 ,@Parm_wkz char(10)
 ,@Parm_eurokurs float
 ,@Parm_eklohn float
 ,@Parm_bruttolohn float
 ,@Parm_bemerkung char(50)
 ,@Parm_PrjNr char(8)
 ,@Parm_ExpTPO tinyint
 ,@Parm_ExpConnect tinyint
 ,@Parm_ExpTopLohn tinyint
 ,@Parm_ExpSPLohn tinyint
 ,@Parm_ExpFibu integer
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_Zeiterfassung] SET
     [arbtnr] = RTRIM(@Parm_arbtnr)
    ,[art] = RTRIM(@Parm_art)
    ,[belegnr] = RTRIM(@Parm_belegnr)
    ,[posnr] = RTRIM(@Parm_posnr)
    ,[lohnart] = RTRIM(@Parm_lohnart)
    ,[tag] = RTRIM(@Parm_tag)
    ,[monat] = RTRIM(@Parm_monat)
    ,[jahr] = RTRIM(@Parm_jahr)
    ,[kstnr] = RTRIM(@Parm_kstnr)
    ,[stunden] = @Parm_stunden
    ,[betrag] = @Parm_betrag
    ,[bsgru] = RTRIM(@Parm_bsgru)
    ,[prsatz] = @Parm_prsatz
    ,[satzstrzei] = RTRIM(@Parm_satzstrzei)
    ,[wkz] = RTRIM(@Parm_wkz)
    ,[eurokurs] = @Parm_eurokurs
    ,[eklohn] = @Parm_eklohn
    ,[bruttolohn] = @Parm_bruttolohn
    ,[bemerkung] = RTRIM(@Parm_bemerkung)
    ,[PrjNr] = RTRIM(@Parm_PrjNr)
    ,[ExpTPO] = @Parm_ExpTPO
    ,[ExpConnect] = @Parm_ExpConnect
    ,[ExpTopLohn] = @Parm_ExpTopLohn
    ,[ExpSPLohn] = @Parm_ExpSPLohn
    ,[ExpFibu] = @Parm_ExpFibu
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Sel_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Sel_Zeiterfassung]
  @RI integer
AS
SELECT
     [arbtnr]
    ,[art]
    ,[belegnr]
    ,[posnr]
    ,[lohnart]
    ,[tag]
    ,[monat]
    ,[jahr]
    ,[kstnr]
    ,[stunden]
    ,[betrag]
    ,[bsgru]
    ,[prsatz]
    ,[satzstrzei]
    ,[wkz]
    ,[eurokurs]
    ,[eklohn]
    ,[bruttolohn]
    ,[bemerkung]
    ,[PrjNr]
    ,[ExpTPO]
    ,[ExpConnect]
    ,[ExpTopLohn]
    ,[ExpSPLohn]
    ,[ExpFibu]
  FROM [dbo].[ut_Zeiterfassung]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Del_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Del_Zeiterfassung]
  @RI integer
AS
  DELETE FROM [dbo].[ut_Zeiterfassung] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Reorg_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Reorg_Zeiterfassung]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_Zeiterfassung] 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_Zeiterfassung] 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_Zeiterfassung] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_Append_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_Append_Zeiterfassung]
  @Parm_arbtnr char(4)
 ,@Parm_art char(2)
 ,@Parm_belegnr char(8)
 ,@Parm_posnr char(20)
 ,@Parm_lohnart char(3)
 ,@Parm_tag char(2)
 ,@Parm_monat char(2)
 ,@Parm_jahr char(4)
 ,@Parm_kstnr char(20)
 ,@Parm_stunden float
 ,@Parm_betrag float
 ,@Parm_bsgru char(2)
 ,@Parm_prsatz float
 ,@Parm_satzstrzei char(1)
 ,@Parm_wkz char(10)
 ,@Parm_eurokurs float
 ,@Parm_eklohn float
 ,@Parm_bruttolohn float
 ,@Parm_bemerkung char(50)
 ,@Parm_PrjNr char(8)
 ,@Parm_ExpTPO tinyint
 ,@Parm_ExpConnect tinyint
 ,@Parm_ExpTopLohn tinyint
 ,@Parm_ExpSPLohn tinyint
 ,@Parm_ExpFibu integer
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_Zeiterfassung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Zeiterfassung] (
    RecId
   ,[arbtnr]
   ,[art]
   ,[belegnr]
   ,[posnr]
   ,[lohnart]
   ,[tag]
   ,[monat]
   ,[jahr]
   ,[kstnr]
   ,[stunden]
   ,[betrag]
   ,[bsgru]
   ,[prsatz]
   ,[satzstrzei]
   ,[wkz]
   ,[eurokurs]
   ,[eklohn]
   ,[bruttolohn]
   ,[bemerkung]
   ,[PrjNr]
   ,[ExpTPO]
   ,[ExpConnect]
   ,[ExpTopLohn]
   ,[ExpSPLohn]
   ,[ExpFibu]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_arbtnr)
   ,RTRIM(@Parm_art)
   ,RTRIM(@Parm_belegnr)
   ,RTRIM(@Parm_posnr)
   ,RTRIM(@Parm_lohnart)
   ,RTRIM(@Parm_tag)
   ,RTRIM(@Parm_monat)
   ,RTRIM(@Parm_jahr)
   ,RTRIM(@Parm_kstnr)
   ,@Parm_stunden
   ,@Parm_betrag
   ,RTRIM(@Parm_bsgru)
   ,@Parm_prsatz
   ,RTRIM(@Parm_satzstrzei)
   ,RTRIM(@Parm_wkz)
   ,@Parm_eurokurs
   ,@Parm_eklohn
   ,@Parm_bruttolohn
   ,RTRIM(@Parm_bemerkung)
   ,RTRIM(@Parm_PrjNr)
   ,@Parm_ExpTPO
   ,@Parm_ExpConnect
   ,@Parm_ExpTopLohn
   ,@Parm_ExpSPLohn
   ,@Parm_ExpFibu
       )
  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_Zeiterfassung')
  DROP PROCEDURE [dbo].[up_TrSel_Zeiterfassung]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Zeiterfassung]
AS
  SELECT   RecId,
      LTRIM(RTRIM([arbtnr]))
      +LTRIM(RTRIM([art]))
      +LTRIM(RTRIM([belegnr]))
      +LTRIM(RTRIM([posnr]))
      +LTRIM(RTRIM([lohnart]))
      +LTRIM(RTRIM([tag]))
      +LTRIM(RTRIM([monat]))
      +LTRIM(RTRIM([jahr]))
      +LTRIM(RTRIM([kstnr]))
      +LTRIM(RTRIM([bsgru]))
      +LTRIM(RTRIM([satzstrzei]))
      +LTRIM(RTRIM([wkz]))
      +LTRIM(RTRIM([bemerkung]))
      +LTRIM(RTRIM([PrjNr]))
    AS Data
  FROM     [dbo].[ut_Zeiterfassung]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key0] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key0_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key0')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key0]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key1] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key1_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key1]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key1')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key1]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key2] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key2_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key2]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key2')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key2]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key3] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key3_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key3]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key3')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key3]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key4] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key4_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key4]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key4')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key4]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key5] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key5_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key5]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key5')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key5]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key6] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key6_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key6]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key6')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key6]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_Key6]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key6_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_Key6]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key6_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_Key6] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key6_Value] > (SELECT [Key6_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key6_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key6] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key6_Value] > (SELECT [Key6_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key6_Value]
GO

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

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

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

CREATE INDEX [Ik_Key7] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key7_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key7]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key7')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key7]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_Key7]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key7_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_Key7]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key7_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_Key7] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key7_Value] > (SELECT [Key7_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key7_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key7] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key7_Value] > (SELECT [Key7_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key7_Value]
GO

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

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

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

CREATE INDEX [Ik_Key8] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key8_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key8]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key8')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key8]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_Key8]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key8_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_Key8]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key8_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_Key8] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key8_Value] > (SELECT [Key8_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key8_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key8] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key8_Value] > (SELECT [Key8_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key8_Value]
GO

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

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

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

CREATE INDEX [Ik_Key9] ON [dbo].[ut_Zeiterfassung_Keys]
( [Key9_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_Key9]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_Key9')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_Key9]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_Key9]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key9_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_Key9]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [Key9_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_Key9] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key9_Value] > (SELECT [Key9_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key9_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_Key9] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [Key9_Value] > (SELECT [Key9_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key9_Value]
GO

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

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

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

CREATE INDEX [Ik_KeyA] ON [dbo].[ut_Zeiterfassung_Keys]
( [KeyA_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_KeyA]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_KeyA')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_KeyA]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_KeyA]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [KeyA_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_KeyA]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [KeyA_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_KeyA] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [KeyA_Value] > (SELECT [KeyA_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KeyA_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_KeyA] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [KeyA_Value] > (SELECT [KeyA_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KeyA_Value]
GO

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

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

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

CREATE INDEX [Ik_KeyB] ON [dbo].[ut_Zeiterfassung_Keys]
( [KeyB_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_First_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_Last_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_Prior_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_Next_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_Prior50_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_Next50_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_FindL_Zeiterfassung_KeyB]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Zeiterfassung_KeyB')
  DROP PROCEDURE [dbo].[up_FindF_Zeiterfassung_KeyB]
GO

CREATE PROCEDURE [dbo].[up_First_Zeiterfassung_KeyB]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [KeyB_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Zeiterfassung_KeyB]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys] ORDER BY [KeyB_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Zeiterfassung_KeyB] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [KeyB_Value] > (SELECT [KeyB_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KeyB_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Zeiterfassung_KeyB] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Zeiterfassung_Keys]
  WHERE [KeyB_Value] > (SELECT [KeyB_Value] FROM [dbo].[ut_Zeiterfassung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KeyB_Value]
GO

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

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

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

