------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_ZeitPosten')
BEGIN
CREATE TABLE [dbo].[ut_ZeitPosten]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[PostenGuid] char(40) DEFAULT ' '
  ,[LfdNr] integer DEFAULT 0
  ,[Datum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Uhrzeit] char(5) DEFAULT ' '
  ,[Annr] char(4) DEFAULT ' '
  ,[Belegnr] char(20) DEFAULT ' '
  ,[StatusNum] integer DEFAULT 0
  ,[StatusText] char(10) DEFAULT ' '
  ,[Comment] char(50) DEFAULT ' '
  ,[TicketGuid] char(40) DEFAULT ' '
  ,[Vkz] integer DEFAULT 0
  ,[Closed] tinyint DEFAULT 0
  ,[ClosedBy] char(40) DEFAULT ' '
  ,[InsertDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[InsertTime] char(5) DEFAULT ' '
  ,[Minuten] integer DEFAULT 0
  ,[Stunden] float DEFAULT 0
  ,[Lohnart] char(3) DEFAULT ' '
  ,[ErrorCode] integer DEFAULT 0
  ,[VerbZeit] tinyint DEFAULT 0
  ,[VerbBeleg] tinyint DEFAULT 0
  ,[Hinweis] char(30) DEFAULT ' '
  CONSTRAINT [Pk_ZeitPosten]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZeitPosten_KeyDel')
  DROP TRIGGER [dbo].[tr_ZeitPosten_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZeitPosten_KeyUpd')
  DROP TRIGGER [dbo].[tr_ZeitPosten_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_ZeitPosten_Keys')
  DROP TABLE [dbo].[ut_ZeitPosten_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'PostenGuid')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [PostenGuid] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] 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_ZeitPosten' and sc.[name] = 'Datum')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Datum] 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_ZeitPosten' and sc.[name] = 'Uhrzeit')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Uhrzeit] 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_ZeitPosten' and sc.[name] = 'Annr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Annr] 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_ZeitPosten' and sc.[name] = 'Belegnr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Belegnr] 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_ZeitPosten' and sc.[name] = 'StatusNum')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [StatusNum] 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_ZeitPosten' and sc.[name] = 'StatusText')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [StatusText] 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_ZeitPosten' and sc.[name] = 'Comment')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Comment] 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_ZeitPosten' and sc.[name] = 'TicketGuid')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [TicketGuid] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Vkz')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Vkz] 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_ZeitPosten' and sc.[name] = 'Closed')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Closed] 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_ZeitPosten' and sc.[name] = 'ClosedBy')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [ClosedBy] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'InsertDate')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [InsertDate] 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_ZeitPosten' and sc.[name] = 'InsertTime')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [InsertTime] 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_ZeitPosten' and sc.[name] = 'Minuten')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Minuten] 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_ZeitPosten' and sc.[name] = 'Stunden')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] 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_ZeitPosten' and sc.[name] = 'Lohnart')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] 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_ZeitPosten' and sc.[name] = 'ErrorCode')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [ErrorCode] 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_ZeitPosten' and sc.[name] = 'VerbZeit')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [VerbZeit] 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_ZeitPosten' and sc.[name] = 'VerbBeleg')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [VerbBeleg] 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_ZeitPosten' and sc.[name] = 'Hinweis')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ADD [Hinweis] char(30) NOT NULL DEFAULT ' '
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'PostenGuid')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [PostenGuid] char(40)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Uhrzeit')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Uhrzeit] char(5)
END
GO
IF 4 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Annr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Annr] char(4)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Belegnr')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Belegnr] char(20)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'StatusText')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [StatusText] char(10)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Comment')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Comment] char(50)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'TicketGuid')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [TicketGuid] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'ClosedBy')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [ClosedBy] char(40)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'InsertTime')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [InsertTime] char(5)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Lohnart')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Lohnart] char(3)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZeitPosten' and sc.[name] = 'Hinweis')
BEGIN
  ALTER TABLE [dbo].[ut_ZeitPosten] ALTER COLUMN [Hinweis] char(30)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'ZeitPosten')
  DROP VIEW [dbo].[ZeitPosten]
GO
CREATE VIEW [dbo].[ZeitPosten] AS
  SELECT * FROM [dbo].[ut_ZeitPosten]
GO
CREATE TABLE [dbo].[ut_ZeitPosten_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(50) NOT NULL
  ,[Key01_Value] CHAR(18) NOT NULL
  ,[Key02_Value] CHAR(37) NOT NULL
  ,[Key03_Value] CHAR(37) NOT NULL
  ,[Key04_Value] CHAR(38) NOT NULL
  ,[Key05_Value] CHAR(38) NOT NULL
  CONSTRAINT [Pk_ut_ZeitPosten_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_ZeitPosten_KeyDel] ON [dbo].[ut_ZeitPosten]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_ZeitPosten_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_ZeitPosten_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(40),[PostenGuid])+STR(RecId,10))
     ,UPPER(STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(convert(char(4),[Annr])+CONVERT(char(10),[Datum],120)+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(CONVERT(char(10),[Datum],120)+convert(char(4),[Annr])+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(STR([Vkz],1,0)+convert(char(4),[Annr])+CONVERT(char(10),[Datum],120)+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(STR([Vkz],1,0)+CONVERT(char(10),[Datum],120)+convert(char(4),[Annr])+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_ZeitPosten_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(40),[PostenGuid])+STR([RecId],10))
   ,[Key01_Value] = UPPER(STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(4),[Annr])+CONVERT(char(10),[Datum],120)+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key03_Value] = UPPER(CONVERT(char(10),[Datum],120)+convert(char(4),[Annr])+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key04_Value] = UPPER(STR([Vkz],1,0)+convert(char(4),[Annr])+CONVERT(char(10),[Datum],120)+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key05_Value] = UPPER(STR([Vkz],1,0)+CONVERT(char(10),[Datum],120)+convert(char(4),[Annr])+convert(char(5),[Uhrzeit])+STR([LfdNr],8,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Add_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Add_ZeitPosten] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_ZeitPosten])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_ZeitPosten] (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_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Upd_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Upd_ZeitPosten]
  @RI integer
 ,@Parm_PostenGuid char(40)
 ,@Parm_LfdNr integer
 ,@Parm_Datum datetime
 ,@Parm_Uhrzeit char(5)
 ,@Parm_Annr char(4)
 ,@Parm_Belegnr char(20)
 ,@Parm_StatusNum integer
 ,@Parm_StatusText char(10)
 ,@Parm_Comment char(50)
 ,@Parm_TicketGuid char(40)
 ,@Parm_Vkz integer
 ,@Parm_Closed tinyint
 ,@Parm_ClosedBy char(40)
 ,@Parm_InsertDate datetime
 ,@Parm_InsertTime char(5)
 ,@Parm_Minuten integer
 ,@Parm_Stunden float
 ,@Parm_Lohnart char(3)
 ,@Parm_ErrorCode integer
 ,@Parm_VerbZeit tinyint
 ,@Parm_VerbBeleg tinyint
 ,@Parm_Hinweis char(30)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_ZeitPosten] SET
     [PostenGuid] = RTRIM(@Parm_PostenGuid)
    ,[LfdNr] = @Parm_LfdNr
    ,[Datum] = @Parm_Datum
    ,[Uhrzeit] = RTRIM(@Parm_Uhrzeit)
    ,[Annr] = RTRIM(@Parm_Annr)
    ,[Belegnr] = RTRIM(@Parm_Belegnr)
    ,[StatusNum] = @Parm_StatusNum
    ,[StatusText] = RTRIM(@Parm_StatusText)
    ,[Comment] = RTRIM(@Parm_Comment)
    ,[TicketGuid] = RTRIM(@Parm_TicketGuid)
    ,[Vkz] = @Parm_Vkz
    ,[Closed] = @Parm_Closed
    ,[ClosedBy] = RTRIM(@Parm_ClosedBy)
    ,[InsertDate] = @Parm_InsertDate
    ,[InsertTime] = RTRIM(@Parm_InsertTime)
    ,[Minuten] = @Parm_Minuten
    ,[Stunden] = @Parm_Stunden
    ,[Lohnart] = RTRIM(@Parm_Lohnart)
    ,[ErrorCode] = @Parm_ErrorCode
    ,[VerbZeit] = @Parm_VerbZeit
    ,[VerbBeleg] = @Parm_VerbBeleg
    ,[Hinweis] = RTRIM(@Parm_Hinweis)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Sel_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Sel_ZeitPosten]
  @RI integer
AS
SELECT
     [PostenGuid]
    ,[LfdNr]
    ,[Datum]
    ,[Uhrzeit]
    ,[Annr]
    ,[Belegnr]
    ,[StatusNum]
    ,[StatusText]
    ,[Comment]
    ,[TicketGuid]
    ,[Vkz]
    ,[Closed]
    ,[ClosedBy]
    ,[InsertDate]
    ,[InsertTime]
    ,[Minuten]
    ,[Stunden]
    ,[Lohnart]
    ,[ErrorCode]
    ,[VerbZeit]
    ,[VerbBeleg]
    ,[Hinweis]
  FROM [dbo].[ut_ZeitPosten]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Del_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Del_ZeitPosten]
  @RI integer
AS
  DELETE FROM [dbo].[ut_ZeitPosten] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Reorg_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Reorg_ZeitPosten]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_ZeitPosten] 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_ZeitPosten] 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_ZeitPosten] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_ZeitPosten')
  DROP PROCEDURE [dbo].[up_Append_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_Append_ZeitPosten]
  @Parm_PostenGuid char(40)
 ,@Parm_LfdNr integer
 ,@Parm_Datum datetime
 ,@Parm_Uhrzeit char(5)
 ,@Parm_Annr char(4)
 ,@Parm_Belegnr char(20)
 ,@Parm_StatusNum integer
 ,@Parm_StatusText char(10)
 ,@Parm_Comment char(50)
 ,@Parm_TicketGuid char(40)
 ,@Parm_Vkz integer
 ,@Parm_Closed tinyint
 ,@Parm_ClosedBy char(40)
 ,@Parm_InsertDate datetime
 ,@Parm_InsertTime char(5)
 ,@Parm_Minuten integer
 ,@Parm_Stunden float
 ,@Parm_Lohnart char(3)
 ,@Parm_ErrorCode integer
 ,@Parm_VerbZeit tinyint
 ,@Parm_VerbBeleg tinyint
 ,@Parm_Hinweis char(30)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_ZeitPosten])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_ZeitPosten] (
    RecId
   ,[PostenGuid]
   ,[LfdNr]
   ,[Datum]
   ,[Uhrzeit]
   ,[Annr]
   ,[Belegnr]
   ,[StatusNum]
   ,[StatusText]
   ,[Comment]
   ,[TicketGuid]
   ,[Vkz]
   ,[Closed]
   ,[ClosedBy]
   ,[InsertDate]
   ,[InsertTime]
   ,[Minuten]
   ,[Stunden]
   ,[Lohnart]
   ,[ErrorCode]
   ,[VerbZeit]
   ,[VerbBeleg]
   ,[Hinweis]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_PostenGuid)
   ,@Parm_LfdNr
   ,@Parm_Datum
   ,RTRIM(@Parm_Uhrzeit)
   ,RTRIM(@Parm_Annr)
   ,RTRIM(@Parm_Belegnr)
   ,@Parm_StatusNum
   ,RTRIM(@Parm_StatusText)
   ,RTRIM(@Parm_Comment)
   ,RTRIM(@Parm_TicketGuid)
   ,@Parm_Vkz
   ,@Parm_Closed
   ,RTRIM(@Parm_ClosedBy)
   ,@Parm_InsertDate
   ,RTRIM(@Parm_InsertTime)
   ,@Parm_Minuten
   ,@Parm_Stunden
   ,RTRIM(@Parm_Lohnart)
   ,@Parm_ErrorCode
   ,@Parm_VerbZeit
   ,@Parm_VerbBeleg
   ,RTRIM(@Parm_Hinweis)
       )
  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_ZeitPosten')
  DROP PROCEDURE [dbo].[up_TrSel_ZeitPosten]
GO
CREATE PROCEDURE [dbo].[up_TrSel_ZeitPosten]
AS
  SELECT   RecId,
      LTRIM(RTRIM([PostenGuid]))
      +LTRIM(RTRIM([Uhrzeit]))
      +LTRIM(RTRIM([Annr]))
      +LTRIM(RTRIM([Belegnr]))
      +LTRIM(RTRIM([StatusText]))
      +LTRIM(RTRIM([Comment]))
      +LTRIM(RTRIM([TicketGuid]))
      +LTRIM(RTRIM([ClosedBy]))
      +LTRIM(RTRIM([InsertTime]))
      +LTRIM(RTRIM([Lohnart]))
      +LTRIM(RTRIM([Hinweis]))
    AS Data
  FROM     [dbo].[ut_ZeitPosten]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_ZeitPosten_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key00')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_ZeitPosten_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key01')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key01]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_ZeitPosten_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key02')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_ZeitPosten_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key03')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key03]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_ZeitPosten_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key04')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key04]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_ZeitPosten_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_First_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_Last_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_Prior_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_Next_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_Next50_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_FindL_ZeitPosten_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZeitPosten_Key05')
  DROP PROCEDURE [dbo].[up_FindF_ZeitPosten_Key05]
GO

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

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

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

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

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

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

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

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

