------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_ZeitKladdenZeile')
BEGIN
CREATE TABLE [dbo].[ut_ZeitKladdenZeile]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Code] char(20) DEFAULT ' '
  ,[LfdNr] integer DEFAULT 0
  ,[Annr] char(8) DEFAULT ' '
  ,[Loa] char(3) DEFAULT ' '
  ,[BuchDatum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[ErfDatum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Beginn] char(5) DEFAULT ' '
  ,[Ende] char(5) DEFAULT ' '
  ,[Stunden] float DEFAULT 0
  ,[Betrag] float DEFAULT 0
  ,[EkLohn] float DEFAULT 0
  ,[Brutto] float DEFAULT 0
  ,[PrjNr] char(8) DEFAULT ' '
  ,[BelArt] char(2) DEFAULT ' '
  ,[BelNr] char(8) DEFAULT ' '
  ,[ExtBelNr] char(20) DEFAULT ' '
  ,[Kst] char(20) DEFAULT ' '
  ,[Ktr] char(20) DEFAULT ' '
  ,[BuText] char(50) DEFAULT ' '
  ,[Herkunft] integer DEFAULT 0
  ,[Gesperrt] tinyint DEFAULT 0
  ,[GebZeitw] tinyint DEFAULT 0
  ,[Vorgang] char(20) DEFAULT ' '
  ,[ServiceBer] char(20) DEFAULT ' '
  ,[AbzugStd] float DEFAULT 0
  CONSTRAINT [Pk_ZeitKladdenZeile]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZeitKladdenZeile_KeyDel')
  DROP TRIGGER [dbo].[tr_ZeitKladdenZeile_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZeitKladdenZeile_KeyUpd')
  DROP TRIGGER [dbo].[tr_ZeitKladdenZeile_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_ZeitKladdenZeile_Keys')
  DROP TABLE [dbo].[ut_ZeitKladdenZeile_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Code')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Code] 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_ZeitKladdenZeile' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [LfdNr] integer 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_ZeitKladdenZeile' and sc.[name] = 'Annr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Annr] 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_ZeitKladdenZeile' and sc.[name] = 'Loa')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Loa] 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_ZeitKladdenZeile' and sc.[name] = 'BuchDatum')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [BuchDatum] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'ErfDatum')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [ErfDatum] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Beginn')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Beginn] char(5) 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_ZeitKladdenZeile' and sc.[name] = 'Ende')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Ende] char(5) 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_ZeitKladdenZeile' and sc.[name] = 'Stunden')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'Betrag')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'EkLohn')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'Brutto')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Brutto] 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_ZeitKladdenZeile' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'ExtBelNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [ExtBelNr] 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_ZeitKladdenZeile' and sc.[name] = 'Kst')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Kst] 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_ZeitKladdenZeile' and sc.[name] = 'Ktr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Ktr] 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_ZeitKladdenZeile' and sc.[name] = 'BuText')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [BuText] 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_ZeitKladdenZeile' and sc.[name] = 'Herkunft')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Herkunft] integer 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_ZeitKladdenZeile' and sc.[name] = 'Gesperrt')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Gesperrt] 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_ZeitKladdenZeile' and sc.[name] = 'GebZeitw')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [GebZeitw] 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_ZeitKladdenZeile' and sc.[name] = 'Vorgang')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [Vorgang] 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_ZeitKladdenZeile' and sc.[name] = 'ServiceBer')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [ServiceBer] 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_ZeitKladdenZeile' and sc.[name] = 'AbzugStd')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ADD [AbzugStd] float NOT NULL DEFAULT 0
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Code')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Code] char(20)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Annr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Annr] char(8)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Loa')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Loa] char(3)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Beginn')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Beginn] char(5)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Ende')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Ende] char(5)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [PrjNr] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [BelNr] char(8)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'ExtBelNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [ExtBelNr] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Kst')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Kst] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Ktr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Ktr] char(20)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'BuText')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [BuText] char(50)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'Vorgang')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [Vorgang] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitKladdenZeile' and sc.[name] = 'ServiceBer')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitKladdenZeile] ALTER COLUMN [ServiceBer] char(20)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'ZeitKladdenZeile')
  DROP VIEW [dbo].[ZeitKladdenZeile]
GO
CREATE VIEW [dbo].[ZeitKladdenZeile] AS
  SELECT RecId
    ,[Code]
    ,[LfdNr]
    ,[Annr]
    ,[Loa]
    ,[BuchDatum]
    ,[ErfDatum]
    ,[Beginn]
    ,[Ende]
    ,[Stunden]
    ,[Betrag]
    ,[EkLohn]
    ,[Brutto]
    ,[PrjNr]
    ,[BelArt]
    ,[BelNr]
    ,[ExtBelNr]
    ,[Kst]
    ,[Ktr]
    ,[BuText]
    ,[Herkunft]
    ,[Gesperrt]
    ,[GebZeitw]
    ,[Vorgang]
    ,[ServiceBer]
    ,[AbzugStd]
  FROM [dbo].[ut_ZeitKladdenZeile]
GO
CREATE TABLE [dbo].[ut_ZeitKladdenZeile_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(38) NOT NULL
  ,[Key01_Filter] TINYINT NOT NULL
  ,[Key01_Value] CHAR(38) NOT NULL
  ,[Key02_Value] CHAR(58) NOT NULL
  ,[Key03_Value] CHAR(39) NOT NULL
  ,[Key04_Value] CHAR(39) NOT NULL
  CONSTRAINT [Pk_ut_ZeitKladdenZeile_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_ZeitKladdenZeile_KeyDel] ON [dbo].[ut_ZeitKladdenZeile]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_ZeitKladdenZeile_Keys] /*WITH (SERIALIZABLE)*/
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

CREATE TRIGGER [dbo].[tr_ZeitKladdenZeile_KeyUpd] ON [dbo].[ut_ZeitKladdenZeile]
FOR INSERT, UPDATE
AS
  SET NOCOUNT ON
  IF UPDATE([RecId]) OR UPDATE([MandId])
  BEGIN
    DELETE FROM [dbo].[ut_ZeitKladdenZeile_Keys] /*WITH (SERIALIZABLE)*/
    WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)

    INSERT INTO [dbo].[ut_ZeitKladdenZeile_Keys] /*WITH (SERIALIZABLE)*/
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Filter],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(20),[Code])+STR([LfdNr],8,0)+STR(RecId,10))
     ,CASE WHEN (0 =  Gesperrt) THEN 1 ELSE 0 END
     ,UPPER(convert(char(20),[Code])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(convert(char(20),[ServiceBer])+convert(char(20),[Code])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(convert(char(20),[Code])+convert(char(1),[Gesperrt])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(convert(char(20),[Code])+convert(char(1),[GebZeitw])+STR([LfdNr],8,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_ZeitKladdenZeile_Keys] /*WITH (SERIALIZABLE)*/ SET
    [Key00_Value] = UPPER(convert(char(20),[Code])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[Code])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key01_Filter] = CASE WHEN (0 =  Gesperrt) THEN 1 ELSE 0 END
   ,[Key02_Value] = UPPER(convert(char(20),[ServiceBer])+convert(char(20),[Code])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(20),[Code])+convert(char(1),[Gesperrt])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(20),[Code])+convert(char(1),[GebZeitw])+STR([LfdNr],8,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF OBJECT_ID (N'itcfunc_NextRecId_ZeitKladdenZeile', N'FN') IS NOT NULL
	DROP FUNCTION dbo.itcfunc_NextRecId_ZeitKladdenZeile
GO
CREATE FUNCTION dbo.itcfunc_NextRecId_ZeitKladdenZeile() RETURNS integer
AS
BEGIN
  RETURN isnull((SELECT MAX(RecId) FROM [dbo].[ut_ZeitKladdenZeile] WITH (READUNCOMMITTED)),0) + 1
END
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Sel_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Sel_ZeitKladdenZeile]
  @RI integer
AS
SELECT
     [Code]
    ,[LfdNr]
    ,[Annr]
    ,[Loa]
    ,[BuchDatum]
    ,[ErfDatum]
    ,[Beginn]
    ,[Ende]
    ,[Stunden]
    ,[Betrag]
    ,[EkLohn]
    ,[Brutto]
    ,[PrjNr]
    ,[BelArt]
    ,[BelNr]
    ,[ExtBelNr]
    ,[Kst]
    ,[Ktr]
    ,[BuText]
    ,[Herkunft]
    ,[Gesperrt]
    ,[GebZeitw]
    ,[Vorgang]
    ,[ServiceBer]
    ,[AbzugStd]
  FROM [dbo].[ut_ZeitKladdenZeile]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel2_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Sel2_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Sel2_ZeitKladdenZeile]
  @Param_RecId varchar(20)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)
  SELECT * FROM [dbo].[ZeitKladdenZeile]
  WHERE RecId = @mRI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P' and [name] = 'up_Append_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Append_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Append_ZeitKladdenZeile]
  @Parm_Code char(20)
 ,@Parm_LfdNr integer
 ,@Parm_Annr char(8)
 ,@Parm_Loa char(3)
 ,@Parm_BuchDatum datetime
 ,@Parm_ErfDatum datetime
 ,@Parm_Beginn char(5)
 ,@Parm_Ende char(5)
 ,@Parm_Stunden float
 ,@Parm_Betrag float
 ,@Parm_EkLohn float
 ,@Parm_Brutto float
 ,@Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_ExtBelNr char(20)
 ,@Parm_Kst char(20)
 ,@Parm_Ktr char(20)
 ,@Parm_BuText char(50)
 ,@Parm_Herkunft integer
 ,@Parm_Gesperrt tinyint
 ,@Parm_GebZeitw tinyint
 ,@Parm_Vorgang char(20)
 ,@Parm_ServiceBer char(20)
 ,@Parm_AbzugStd float
AS
  DECLARE @NeueId integer
  DECLARE @m_CountDown integer = 10
  WHILE @m_CountDown > 0 BEGIN
    BEGIN TRANSACTION
    BEGIN TRY
      SET @NeueId = dbo.itcfunc_NextRecId_ZeitKladdenZeile()
      INSERT INTO [dbo].[ut_ZeitKladdenZeile] (RecId
       ,[Code]
       ,[LfdNr]
       ,[Annr]
       ,[Loa]
       ,[BuchDatum]
       ,[ErfDatum]
       ,[Beginn]
       ,[Ende]
       ,[Stunden]
       ,[Betrag]
       ,[EkLohn]
       ,[Brutto]
       ,[PrjNr]
       ,[BelArt]
       ,[BelNr]
       ,[ExtBelNr]
       ,[Kst]
       ,[Ktr]
       ,[BuText]
       ,[Herkunft]
       ,[Gesperrt]
       ,[GebZeitw]
       ,[Vorgang]
       ,[ServiceBer]
       ,[AbzugStd]
         ) VALUES (@NeueId
       ,RTRIM(@Parm_Code)
       ,@Parm_LfdNr
       ,RTRIM(@Parm_Annr)
       ,RTRIM(@Parm_Loa)
       ,@Parm_BuchDatum
       ,@Parm_ErfDatum
       ,RTRIM(@Parm_Beginn)
       ,RTRIM(@Parm_Ende)
       ,@Parm_Stunden
       ,@Parm_Betrag
       ,@Parm_EkLohn
       ,@Parm_Brutto
       ,RTRIM(@Parm_PrjNr)
       ,RTRIM(@Parm_BelArt)
       ,RTRIM(@Parm_BelNr)
       ,RTRIM(@Parm_ExtBelNr)
       ,RTRIM(@Parm_Kst)
       ,RTRIM(@Parm_Ktr)
       ,RTRIM(@Parm_BuText)
       ,@Parm_Herkunft
       ,@Parm_Gesperrt
       ,@Parm_GebZeitw
       ,RTRIM(@Parm_Vorgang)
       ,RTRIM(@Parm_ServiceBer)
       ,@Parm_AbzugStd
           )
      COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
      ROLLBACK TRANSACTION
      SET @NeueId = 0
    END CATCH

    IF @NeueId <> 0
      SET @m_CountDown = 0
    ELSE
      SET @m_CountDown = @m_CountDown - 1

    IF @m_CountDown > 0
      WAITFOR DELAY '00:00:00.050'
  END
  SELECT @NeueId AS RecId
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Upd_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Upd_ZeitKladdenZeile]
  @RI integer
 ,@Parm_Code char(20)
 ,@Parm_LfdNr integer
 ,@Parm_Annr char(8)
 ,@Parm_Loa char(3)
 ,@Parm_BuchDatum datetime
 ,@Parm_ErfDatum datetime
 ,@Parm_Beginn char(5)
 ,@Parm_Ende char(5)
 ,@Parm_Stunden float
 ,@Parm_Betrag float
 ,@Parm_EkLohn float
 ,@Parm_Brutto float
 ,@Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_ExtBelNr char(20)
 ,@Parm_Kst char(20)
 ,@Parm_Ktr char(20)
 ,@Parm_BuText char(50)
 ,@Parm_Herkunft integer
 ,@Parm_Gesperrt tinyint
 ,@Parm_GebZeitw tinyint
 ,@Parm_Vorgang char(20)
 ,@Parm_ServiceBer char(20)
 ,@Parm_AbzugStd float
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_ZeitKladdenZeile] SET
     [Code] = RTRIM(@Parm_Code)
    ,[LfdNr] = @Parm_LfdNr
    ,[Annr] = RTRIM(@Parm_Annr)
    ,[Loa] = RTRIM(@Parm_Loa)
    ,[BuchDatum] = @Parm_BuchDatum
    ,[ErfDatum] = @Parm_ErfDatum
    ,[Beginn] = RTRIM(@Parm_Beginn)
    ,[Ende] = RTRIM(@Parm_Ende)
    ,[Stunden] = @Parm_Stunden
    ,[Betrag] = @Parm_Betrag
    ,[EkLohn] = @Parm_EkLohn
    ,[Brutto] = @Parm_Brutto
    ,[PrjNr] = RTRIM(@Parm_PrjNr)
    ,[BelArt] = RTRIM(@Parm_BelArt)
    ,[BelNr] = RTRIM(@Parm_BelNr)
    ,[ExtBelNr] = RTRIM(@Parm_ExtBelNr)
    ,[Kst] = RTRIM(@Parm_Kst)
    ,[Ktr] = RTRIM(@Parm_Ktr)
    ,[BuText] = RTRIM(@Parm_BuText)
    ,[Herkunft] = @Parm_Herkunft
    ,[Gesperrt] = @Parm_Gesperrt
    ,[GebZeitw] = @Parm_GebZeitw
    ,[Vorgang] = RTRIM(@Parm_Vorgang)
    ,[ServiceBer] = RTRIM(@Parm_ServiceBer)
    ,[AbzugStd] = @Parm_AbzugStd
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd2_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Upd2_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Upd2_ZeitKladdenZeile]
  @Param_RecId varchar(20)
 ,@Param_Code varchar(20)
 ,@Param_LfdNr varchar(20)
 ,@Param_Annr varchar(8)
 ,@Param_Loa varchar(3)
 ,@Param_BuchDatum varchar(10)
 ,@Param_ErfDatum varchar(10)
 ,@Param_Beginn varchar(5)
 ,@Param_Ende varchar(5)
 ,@Param_Stunden varchar(20)
 ,@Param_Betrag varchar(20)
 ,@Param_EkLohn varchar(20)
 ,@Param_Brutto varchar(20)
 ,@Param_PrjNr varchar(8)
 ,@Param_BelArt varchar(2)
 ,@Param_BelNr varchar(8)
 ,@Param_ExtBelNr varchar(20)
 ,@Param_Kst varchar(20)
 ,@Param_Ktr varchar(20)
 ,@Param_BuText varchar(50)
 ,@Param_Herkunft varchar(20)
 ,@Param_Gesperrt varchar(10)
 ,@Param_GebZeitw varchar(10)
 ,@Param_Vorgang varchar(20)
 ,@Param_ServiceBer varchar(20)
 ,@Param_AbzugStd varchar(20)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)

  UPDATE [dbo].[ut_ZeitKladdenZeile] SET
     [Code] = UPPER(RTRIM(@Param_Code))
    ,[LfdNr] = dbo.itcfunc_float(@Param_LfdNr)
    ,[Annr] = UPPER(RTRIM(@Param_Annr))
    ,[Loa] = UPPER(RTRIM(@Param_Loa))
    ,[BuchDatum] = dbo.itcfunc_datetime(@Param_BuchDatum)
    ,[ErfDatum] = dbo.itcfunc_datetime(@Param_ErfDatum)
    ,[Beginn] = UPPER(RTRIM(@Param_Beginn))
    ,[Ende] = UPPER(RTRIM(@Param_Ende))
    ,[Stunden] = dbo.itcfunc_float(@Param_Stunden)
    ,[Betrag] = dbo.itcfunc_float(@Param_Betrag)
    ,[EkLohn] = dbo.itcfunc_float(@Param_EkLohn)
    ,[Brutto] = dbo.itcfunc_float(@Param_Brutto)
    ,[PrjNr] = UPPER(RTRIM(@Param_PrjNr))
    ,[BelArt] = UPPER(RTRIM(@Param_BelArt))
    ,[BelNr] = UPPER(RTRIM(@Param_BelNr))
    ,[ExtBelNr] = UPPER(RTRIM(@Param_ExtBelNr))
    ,[Kst] = UPPER(RTRIM(@Param_Kst))
    ,[Ktr] = UPPER(RTRIM(@Param_Ktr))
    ,[BuText] = RTRIM(@Param_BuText)
    ,[Herkunft] = dbo.itcfunc_float(@Param_Herkunft)
    ,[Gesperrt] = dbo.itcfunc_integer(@Param_Gesperrt)
    ,[GebZeitw] = dbo.itcfunc_integer(@Param_GebZeitw)
    ,[Vorgang] = UPPER(RTRIM(@Param_Vorgang))
    ,[ServiceBer] = UPPER(RTRIM(@Param_ServiceBer))
    ,[AbzugStd] = dbo.itcfunc_float(@Param_AbzugStd)
  WHERE RecId = @mRI

  EXECUTE [dbo].[up_Sel2_ZeitKladdenZeile] @mRI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_TrSel_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_TrSel_ZeitKladdenZeile]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Code]))
      +LTRIM(RTRIM([Annr]))
      +LTRIM(RTRIM([Loa]))
      +LTRIM(RTRIM([Beginn]))
      +LTRIM(RTRIM([Ende]))
      +LTRIM(RTRIM([PrjNr]))
      +LTRIM(RTRIM([BelArt]))
      +LTRIM(RTRIM([BelNr]))
      +LTRIM(RTRIM([ExtBelNr]))
      +LTRIM(RTRIM([Kst]))
      +LTRIM(RTRIM([Ktr]))
      +LTRIM(RTRIM([BuText]))
      +LTRIM(RTRIM([Vorgang]))
      +LTRIM(RTRIM([ServiceBer]))
    AS Data
  FROM     [dbo].[ut_ZeitKladdenZeile]
  WHERE    RecId > 0
  ORDER BY RecId
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Add_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Add_ZeitKladdenZeile] AS
  DECLARE @NeueId integer = dbo.itcfunc_NextRecId_ZeitKladdenZeile()
  INSERT INTO [dbo].[ut_ZeitKladdenZeile] (RecId) VALUES( @NeueId )
  IF @@ERROR = 0
    SELECT @NeueId AS RecId
  ELSE
    SELECT 0 AS RecId
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Del_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Del_ZeitKladdenZeile]
  @RI integer
AS
  DELETE FROM [dbo].[ut_ZeitKladdenZeile] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_ZeitKladdenZeile')
  DROP PROCEDURE [dbo].[up_Reorg_ZeitKladdenZeile]
GO
CREATE PROCEDURE [dbo].[up_Reorg_ZeitKladdenZeile]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_ZeitKladdenZeile] 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_ZeitKladdenZeile] 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_ZeitKladdenZeile] )
  END
GO


CREATE INDEX [Ik_Key00] ON [dbo].[ut_ZeitKladdenZeile_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 = (select count(*)
   from       sysindexes si
   inner join sysobjects so on
   so.[xtype]    = 'U'
   and so.[name] = 'ut_ZeitKladdenZeile'
   and so.[id]   = si.[id]
   and si.[name] = 'Ik_Key00')
CREATE INDEX [Ik_Key00] ON [dbo].[ut_ZeitKladdenZeile]
(Code,LfdNr,RecId)
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_Prior_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_Next_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_FindL_ZeitKladdenZeile_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitKladdenZeile_Key00')
  DROP PROCEDURE [dbo].[up_FindF_ZeitKladdenZeile_Key00]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_ZeitKladdenZeile_Keys]
( [Key01_Filter],[Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_Prior_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_Next_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_FindL_ZeitKladdenZeile_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitKladdenZeile_Key01')
  DROP PROCEDURE [dbo].[up_FindF_ZeitKladdenZeile_Key01]
GO

CREATE PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZeitKladdenZeile_Keys]
  WHERE [Key01_Filter] = 1 ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZeitKladdenZeile_Keys]
  WHERE [Key01_Filter] = 1 ORDER BY [Key01_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZeitKladdenZeile_Keys]
  WHERE [Key01_Filter] = 1 AND [Key01_Value] > (SELECT [Key01_Value] FROM [dbo].[ut_ZeitKladdenZeile_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZeitKladdenZeile_Keys]
  WHERE [Key01_Filter] = 1 AND [Key01_Value] < (SELECT [Key01_Value] FROM [dbo].[ut_ZeitKladdenZeile_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value] DESC
GO

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_ZeitKladdenZeile_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 = (select count(*)
   from       sysindexes si
   inner join sysobjects so on
   so.[xtype]    = 'U'
   and so.[name] = 'ut_ZeitKladdenZeile'
   and so.[id]   = si.[id]
   and si.[name] = 'Ik_Key02')
CREATE INDEX [Ik_Key02] ON [dbo].[ut_ZeitKladdenZeile]
(ServiceBer,Code,LfdNr,RecId)
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_Prior_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_Next_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_FindL_ZeitKladdenZeile_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitKladdenZeile_Key02')
  DROP PROCEDURE [dbo].[up_FindF_ZeitKladdenZeile_Key02]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_ZeitKladdenZeile_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 = (select count(*)
   from       sysindexes si
   inner join sysobjects so on
   so.[xtype]    = 'U'
   and so.[name] = 'ut_ZeitKladdenZeile'
   and so.[id]   = si.[id]
   and si.[name] = 'Ik_Key03')
CREATE INDEX [Ik_Key03] ON [dbo].[ut_ZeitKladdenZeile]
(Code,Gesperrt,LfdNr,RecId)
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_Prior_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_Next_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_FindL_ZeitKladdenZeile_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitKladdenZeile_Key03')
  DROP PROCEDURE [dbo].[up_FindF_ZeitKladdenZeile_Key03]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_ZeitKladdenZeile_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 = (select count(*)
   from       sysindexes si
   inner join sysobjects so on
   so.[xtype]    = 'U'
   and so.[name] = 'ut_ZeitKladdenZeile'
   and so.[id]   = si.[id]
   and si.[name] = 'Ik_Key04')
CREATE INDEX [Ik_Key04] ON [dbo].[ut_ZeitKladdenZeile]
(Code,GebZeitw,LfdNr,RecId)
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_First_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_Last_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_Prior_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_Next_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_Next50_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_FindL_ZeitKladdenZeile_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitKladdenZeile_Key04')
  DROP PROCEDURE [dbo].[up_FindF_ZeitKladdenZeile_Key04]
GO

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

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

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

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

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

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

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

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

