------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelFormLineTypes')
BEGIN
CREATE TABLE [dbo].[ut_BelFormLineTypes]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[FormNr] integer DEFAULT 0
  ,[PageId] integer DEFAULT 0
  ,[ZeilenTyp] char(20) DEFAULT ' '
  ,[SubTyp] integer DEFAULT 0
  ,[LfdNr] integer DEFAULT 0
  ,[Field0] char(14) DEFAULT ' '
  ,[Field1] char(14) DEFAULT ' '
  ,[Field2] char(14) DEFAULT ' '
  ,[Field3] char(14) DEFAULT ' '
  ,[Field4] char(14) DEFAULT ' '
  ,[Field5] char(14) DEFAULT ' '
  ,[Field6] char(14) DEFAULT ' '
  ,[Field7] char(14) DEFAULT ' '
  ,[Field8] char(14) DEFAULT ' '
  ,[Field9] char(14) DEFAULT ' '
  ,[PosRef] char(6) DEFAULT ' '
  ,[Uebertrag] char(14) DEFAULT ' '
  ,[TypGruppe] char(2) DEFAULT ' '
  CONSTRAINT [Pk_BelFormLineTypes]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormLineTypes_KeyDel')
  DROP TRIGGER [dbo].[tr_BelFormLineTypes_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormLineTypes_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelFormLineTypes_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelFormLineTypes_Keys')
  DROP TABLE [dbo].[ut_BelFormLineTypes_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'FormNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [FormNr] 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_BelFormLineTypes' and sc.[name] = 'PageId')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [PageId] 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_BelFormLineTypes' and sc.[name] = 'ZeilenTyp')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [ZeilenTyp] 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_BelFormLineTypes' and sc.[name] = 'SubTyp')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [SubTyp] 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_BelFormLineTypes' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] 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_BelFormLineTypes' and sc.[name] = 'Field0')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field0] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field1')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field1] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field2')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field2] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field3')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field3] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field4')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field4] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field5')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field5] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field6')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field6] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field7')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field7] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field8')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field8] char(14) 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_BelFormLineTypes' and sc.[name] = 'Field9')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Field9] char(14) 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_BelFormLineTypes' and sc.[name] = 'PosRef')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [PosRef] char(6) 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_BelFormLineTypes' and sc.[name] = 'Uebertrag')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [Uebertrag] char(14) 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_BelFormLineTypes' and sc.[name] = 'TypGruppe')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ADD [TypGruppe] char(2) NOT NULL DEFAULT ' '
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'ZeilenTyp')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [ZeilenTyp] char(20)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field0')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field0] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field1')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field1] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field2')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field2] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field3')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field3] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field4')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field4] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field5')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field5] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field6')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field6] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field7')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field7] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field8')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field8] char(14)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Field9')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Field9] char(14)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'PosRef')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [PosRef] char(6)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'Uebertrag')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [Uebertrag] char(14)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineTypes' and sc.[name] = 'TypGruppe')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineTypes] ALTER COLUMN [TypGruppe] char(2)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelFormLineTypes')
  DROP VIEW [dbo].[BelFormLineTypes]
GO
CREATE VIEW [dbo].[BelFormLineTypes] AS
  SELECT * FROM [dbo].[ut_BelFormLineTypes]
GO
CREATE TABLE [dbo].[ut_BelFormLineTypes_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(49) NOT NULL
  ,[Key01_Value] CHAR(26) NOT NULL
  ,[Key02_Value] CHAR(48) NOT NULL
  ,[Key03_Value] CHAR(28) NOT NULL
  CONSTRAINT [Pk_ut_BelFormLineTypes_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_BelFormLineTypes_KeyDel] ON [dbo].[ut_BelFormLineTypes]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_BelFormLineTypes_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_BelFormLineTypes_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([FormNr],8,0)+STR([PageId],1,0)+convert(char(20),[ZeilenTyp])+STR([SubTyp],4,0)+convert(char(6),[PosRef])+STR(RecId,10))
     ,UPPER(STR([FormNr],8,0)+STR([LfdNr],8,0)+STR(RecId,10))
     ,UPPER(STR([FormNr],8,0)+convert(char(6),[PosRef])+convert(char(20),[ZeilenTyp])+STR([SubTyp],4,0)+STR(RecId,10))
     ,UPPER(STR([FormNr],8,0)+convert(char(2),[TypGruppe])+STR([LfdNr],8,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_BelFormLineTypes_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([FormNr],8,0)+STR([PageId],1,0)+convert(char(20),[ZeilenTyp])+STR([SubTyp],4,0)+convert(char(6),[PosRef])+STR([RecId],10))
   ,[Key01_Value] = UPPER(STR([FormNr],8,0)+STR([LfdNr],8,0)+STR([RecId],10))
   ,[Key02_Value] = UPPER(STR([FormNr],8,0)+convert(char(6),[PosRef])+convert(char(20),[ZeilenTyp])+STR([SubTyp],4,0)+STR([RecId],10))
   ,[Key03_Value] = UPPER(STR([FormNr],8,0)+convert(char(2),[TypGruppe])+STR([LfdNr],8,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Add_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Add_BelFormLineTypes] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_BelFormLineTypes])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormLineTypes] (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_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Upd_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelFormLineTypes]
  @RI integer
 ,@Parm_FormNr integer
 ,@Parm_PageId integer
 ,@Parm_ZeilenTyp char(20)
 ,@Parm_SubTyp integer
 ,@Parm_LfdNr integer
 ,@Parm_Field0 char(14)
 ,@Parm_Field1 char(14)
 ,@Parm_Field2 char(14)
 ,@Parm_Field3 char(14)
 ,@Parm_Field4 char(14)
 ,@Parm_Field5 char(14)
 ,@Parm_Field6 char(14)
 ,@Parm_Field7 char(14)
 ,@Parm_Field8 char(14)
 ,@Parm_Field9 char(14)
 ,@Parm_PosRef char(6)
 ,@Parm_Uebertrag char(14)
 ,@Parm_TypGruppe char(2)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_BelFormLineTypes] SET
     [FormNr] = @Parm_FormNr
    ,[PageId] = @Parm_PageId
    ,[ZeilenTyp] = RTRIM(@Parm_ZeilenTyp)
    ,[SubTyp] = @Parm_SubTyp
    ,[LfdNr] = @Parm_LfdNr
    ,[Field0] = RTRIM(@Parm_Field0)
    ,[Field1] = RTRIM(@Parm_Field1)
    ,[Field2] = RTRIM(@Parm_Field2)
    ,[Field3] = RTRIM(@Parm_Field3)
    ,[Field4] = RTRIM(@Parm_Field4)
    ,[Field5] = RTRIM(@Parm_Field5)
    ,[Field6] = RTRIM(@Parm_Field6)
    ,[Field7] = RTRIM(@Parm_Field7)
    ,[Field8] = RTRIM(@Parm_Field8)
    ,[Field9] = RTRIM(@Parm_Field9)
    ,[PosRef] = RTRIM(@Parm_PosRef)
    ,[Uebertrag] = RTRIM(@Parm_Uebertrag)
    ,[TypGruppe] = RTRIM(@Parm_TypGruppe)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Sel_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelFormLineTypes]
  @RI integer
AS
SELECT
     [FormNr]
    ,[PageId]
    ,[ZeilenTyp]
    ,[SubTyp]
    ,[LfdNr]
    ,[Field0]
    ,[Field1]
    ,[Field2]
    ,[Field3]
    ,[Field4]
    ,[Field5]
    ,[Field6]
    ,[Field7]
    ,[Field8]
    ,[Field9]
    ,[PosRef]
    ,[Uebertrag]
    ,[TypGruppe]
  FROM [dbo].[ut_BelFormLineTypes]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Del_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Del_BelFormLineTypes]
  @RI integer
AS
  DELETE FROM [dbo].[ut_BelFormLineTypes] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Reorg_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelFormLineTypes]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelFormLineTypes] 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_BelFormLineTypes] 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_BelFormLineTypes] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_Append_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_Append_BelFormLineTypes]
  @Parm_FormNr integer
 ,@Parm_PageId integer
 ,@Parm_ZeilenTyp char(20)
 ,@Parm_SubTyp integer
 ,@Parm_LfdNr integer
 ,@Parm_Field0 char(14)
 ,@Parm_Field1 char(14)
 ,@Parm_Field2 char(14)
 ,@Parm_Field3 char(14)
 ,@Parm_Field4 char(14)
 ,@Parm_Field5 char(14)
 ,@Parm_Field6 char(14)
 ,@Parm_Field7 char(14)
 ,@Parm_Field8 char(14)
 ,@Parm_Field9 char(14)
 ,@Parm_PosRef char(6)
 ,@Parm_Uebertrag char(14)
 ,@Parm_TypGruppe char(2)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_BelFormLineTypes])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormLineTypes] (
    RecId
   ,[FormNr]
   ,[PageId]
   ,[ZeilenTyp]
   ,[SubTyp]
   ,[LfdNr]
   ,[Field0]
   ,[Field1]
   ,[Field2]
   ,[Field3]
   ,[Field4]
   ,[Field5]
   ,[Field6]
   ,[Field7]
   ,[Field8]
   ,[Field9]
   ,[PosRef]
   ,[Uebertrag]
   ,[TypGruppe]
     ) VALUES (
    @NeueId
   ,@Parm_FormNr
   ,@Parm_PageId
   ,RTRIM(@Parm_ZeilenTyp)
   ,@Parm_SubTyp
   ,@Parm_LfdNr
   ,RTRIM(@Parm_Field0)
   ,RTRIM(@Parm_Field1)
   ,RTRIM(@Parm_Field2)
   ,RTRIM(@Parm_Field3)
   ,RTRIM(@Parm_Field4)
   ,RTRIM(@Parm_Field5)
   ,RTRIM(@Parm_Field6)
   ,RTRIM(@Parm_Field7)
   ,RTRIM(@Parm_Field8)
   ,RTRIM(@Parm_Field9)
   ,RTRIM(@Parm_PosRef)
   ,RTRIM(@Parm_Uebertrag)
   ,RTRIM(@Parm_TypGruppe)
       )
  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_BelFormLineTypes')
  DROP PROCEDURE [dbo].[up_TrSel_BelFormLineTypes]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelFormLineTypes]
AS
  SELECT   RecId,
      LTRIM(RTRIM([ZeilenTyp]))
      +LTRIM(RTRIM([Field0]))
      +LTRIM(RTRIM([Field1]))
      +LTRIM(RTRIM([Field2]))
      +LTRIM(RTRIM([Field3]))
      +LTRIM(RTRIM([Field4]))
      +LTRIM(RTRIM([Field5]))
      +LTRIM(RTRIM([Field6]))
      +LTRIM(RTRIM([Field7]))
      +LTRIM(RTRIM([Field8]))
      +LTRIM(RTRIM([Field9]))
      +LTRIM(RTRIM([PosRef]))
      +LTRIM(RTRIM([Uebertrag]))
      +LTRIM(RTRIM([TypGruppe]))
    AS Data
  FROM     [dbo].[ut_BelFormLineTypes]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_BelFormLineTypes_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_First_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_Last_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_Prior_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_Next_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_Next50_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_FindL_BelFormLineTypes_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormLineTypes_Key00')
  DROP PROCEDURE [dbo].[up_FindF_BelFormLineTypes_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_BelFormLineTypes_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_First_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_Last_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_Prior_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_Next_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_Next50_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_FindL_BelFormLineTypes_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormLineTypes_Key01')
  DROP PROCEDURE [dbo].[up_FindF_BelFormLineTypes_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_BelFormLineTypes_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_First_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_Last_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_Prior_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_Next_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_Next50_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_FindL_BelFormLineTypes_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormLineTypes_Key02')
  DROP PROCEDURE [dbo].[up_FindF_BelFormLineTypes_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_BelFormLineTypes_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_First_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_Last_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_Prior_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_Next_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_Next50_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_FindL_BelFormLineTypes_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormLineTypes_Key03')
  DROP PROCEDURE [dbo].[up_FindF_BelFormLineTypes_Key03]
GO

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

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

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

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

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

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

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

