------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelPosDisplay')
BEGIN
CREATE TABLE [dbo].[ut_BelPosDisplay]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[ZeilenId] integer DEFAULT 0
  ,[ZeilenNr] integer DEFAULT 0
  ,[Summe] integer DEFAULT 0
  ,[Titel] integer DEFAULT 0
  ,[Paket] integer DEFAULT 0
  ,[Leistung] integer DEFAULT 0
  ,[Zubehoer] integer DEFAULT 0
  ,[Titel1] char(30) DEFAULT ' '
  ,[Field1] char(14) DEFAULT ' '
  ,[Color1] integer DEFAULT 0
  ,[Titel2] char(30) DEFAULT ' '
  ,[Field2] char(14) DEFAULT ' '
  ,[Color2] integer DEFAULT 0
  ,[Titel3] char(30) DEFAULT ' '
  ,[Field3] char(14) DEFAULT ' '
  ,[Color3] integer DEFAULT 0
  ,[Titel4] char(30) DEFAULT ' '
  ,[Field4] char(14) DEFAULT ' '
  ,[Color4] integer DEFAULT 0
  ,[Titel5] char(30) DEFAULT ' '
  ,[Field5] char(14) DEFAULT ' '
  ,[Color5] integer DEFAULT 0
  ,[Titel6] char(30) DEFAULT ' '
  ,[Field6] char(14) DEFAULT ' '
  ,[Color6] integer DEFAULT 0
  ,[Titel7] char(30) DEFAULT ' '
  ,[Field7] char(14) DEFAULT ' '
  ,[Color7] integer DEFAULT 0
  ,[Titel8] char(30) DEFAULT ' '
  ,[Field8] char(14) DEFAULT ' '
  ,[Color8] integer DEFAULT 0
  ,[Titel9] char(30) DEFAULT ' '
  ,[Field9] char(14) DEFAULT ' '
  ,[Color9] integer DEFAULT 0
  ,[Titel10] char(30) DEFAULT ' '
  ,[Field10] char(14) DEFAULT ' '
  ,[Color10] integer DEFAULT 0
  CONSTRAINT [Pk_BelPosDisplay]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelPosDisplay_KeyDel')
  DROP TRIGGER [dbo].[tr_BelPosDisplay_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelPosDisplay_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelPosDisplay_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelPosDisplay_Keys')
  DROP TABLE [dbo].[ut_BelPosDisplay_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'ZeilenId')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [ZeilenId] 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_BelPosDisplay' and sc.[name] = 'ZeilenNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [ZeilenNr] 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_BelPosDisplay' and sc.[name] = 'Summe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Summe] 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_BelPosDisplay' and sc.[name] = 'Titel')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel] 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_BelPosDisplay' and sc.[name] = 'Paket')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Paket] 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_BelPosDisplay' and sc.[name] = 'Leistung')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Leistung] 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_BelPosDisplay' and sc.[name] = 'Zubehoer')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Zubehoer] 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_BelPosDisplay' and sc.[name] = 'Titel1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel1] char(30) 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_BelPosDisplay' and sc.[name] = 'Field1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color1] 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_BelPosDisplay' and sc.[name] = 'Titel2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel2] char(30) 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_BelPosDisplay' and sc.[name] = 'Field2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color2] 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_BelPosDisplay' and sc.[name] = 'Titel3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel3] char(30) 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_BelPosDisplay' and sc.[name] = 'Field3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color3] 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_BelPosDisplay' and sc.[name] = 'Titel4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel4] char(30) 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_BelPosDisplay' and sc.[name] = 'Field4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color4] 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_BelPosDisplay' and sc.[name] = 'Titel5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel5] char(30) 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_BelPosDisplay' and sc.[name] = 'Field5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color5] 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_BelPosDisplay' and sc.[name] = 'Titel6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel6] char(30) 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_BelPosDisplay' and sc.[name] = 'Field6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color6] 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_BelPosDisplay' and sc.[name] = 'Titel7')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel7] char(30) 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_BelPosDisplay' and sc.[name] = 'Field7')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color7')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color7] 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_BelPosDisplay' and sc.[name] = 'Titel8')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel8] char(30) 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_BelPosDisplay' and sc.[name] = 'Field8')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color8')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color8] 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_BelPosDisplay' and sc.[name] = 'Titel9')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel9] char(30) 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_BelPosDisplay' and sc.[name] = 'Field9')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] 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_BelPosDisplay' and sc.[name] = 'Color9')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color9] 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_BelPosDisplay' and sc.[name] = 'Titel10')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Titel10] char(30) 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_BelPosDisplay' and sc.[name] = 'Field10')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Field10] 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_BelPosDisplay' and sc.[name] = 'Color10')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ADD [Color10] integer NOT NULL DEFAULT 0
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel1] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field1] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel2] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field2] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel3] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field3] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel4] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field4] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel5] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field5] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel6] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field6] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel7')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel7] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field7')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field7] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel8')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel8] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field8')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field8] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel9')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel9] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field9')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field9] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Titel10')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Titel10] char(30)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPosDisplay' and sc.[name] = 'Field10')
BEGIN
  ALTER TABLE [dbo].[ut_BelPosDisplay] ALTER COLUMN [Field10] char(14)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelPosDisplay')
  DROP VIEW [dbo].[BelPosDisplay]
GO
CREATE VIEW [dbo].[BelPosDisplay] AS
  SELECT * FROM [dbo].[ut_BelPosDisplay]
GO
CREATE TABLE [dbo].[ut_BelPosDisplay_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(14) NOT NULL
  ,[Key01_Value] CHAR(13) NOT NULL
  ,[Key02_Value] CHAR(13) NOT NULL
  ,[Key03_Value] CHAR(13) NOT NULL
  ,[Key04_Value] CHAR(13) NOT NULL
  ,[Key05_Value] CHAR(13) NOT NULL
  CONSTRAINT [Pk_ut_BelPosDisplay_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_BelPosDisplay_KeyDel] ON [dbo].[ut_BelPosDisplay]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_BelPosDisplay_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_BelPosDisplay_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([ZeilenId],4,0)+STR(RecId,10))
     ,UPPER(STR([Summe],1,0)+STR([ZeilenNr],2,0)+STR(RecId,10))
     ,UPPER(STR([Titel],1,0)+STR([ZeilenNr],2,0)+STR(RecId,10))
     ,UPPER(STR([Paket],1,0)+STR([ZeilenNr],2,0)+STR(RecId,10))
     ,UPPER(STR([Leistung],1,0)+STR([ZeilenNr],2,0)+STR(RecId,10))
     ,UPPER(STR([Zubehoer],1,0)+STR([ZeilenNr],2,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_BelPosDisplay_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([ZeilenId],4,0)+STR([RecId],10))
   ,[Key01_Value] = UPPER(STR([Summe],1,0)+STR([ZeilenNr],2,0)+STR([RecId],10))
   ,[Key02_Value] = UPPER(STR([Titel],1,0)+STR([ZeilenNr],2,0)+STR([RecId],10))
   ,[Key03_Value] = UPPER(STR([Paket],1,0)+STR([ZeilenNr],2,0)+STR([RecId],10))
   ,[Key04_Value] = UPPER(STR([Leistung],1,0)+STR([ZeilenNr],2,0)+STR([RecId],10))
   ,[Key05_Value] = UPPER(STR([Zubehoer],1,0)+STR([ZeilenNr],2,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Add_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Add_BelPosDisplay] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_BelPosDisplay])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelPosDisplay] (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_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Upd_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelPosDisplay]
  @RI integer
 ,@Parm_ZeilenId integer
 ,@Parm_ZeilenNr integer
 ,@Parm_Summe integer
 ,@Parm_Titel integer
 ,@Parm_Paket integer
 ,@Parm_Leistung integer
 ,@Parm_Zubehoer integer
 ,@Parm_Titel1 char(30)
 ,@Parm_Field1 char(14)
 ,@Parm_Color1 integer
 ,@Parm_Titel2 char(30)
 ,@Parm_Field2 char(14)
 ,@Parm_Color2 integer
 ,@Parm_Titel3 char(30)
 ,@Parm_Field3 char(14)
 ,@Parm_Color3 integer
 ,@Parm_Titel4 char(30)
 ,@Parm_Field4 char(14)
 ,@Parm_Color4 integer
 ,@Parm_Titel5 char(30)
 ,@Parm_Field5 char(14)
 ,@Parm_Color5 integer
 ,@Parm_Titel6 char(30)
 ,@Parm_Field6 char(14)
 ,@Parm_Color6 integer
 ,@Parm_Titel7 char(30)
 ,@Parm_Field7 char(14)
 ,@Parm_Color7 integer
 ,@Parm_Titel8 char(30)
 ,@Parm_Field8 char(14)
 ,@Parm_Color8 integer
 ,@Parm_Titel9 char(30)
 ,@Parm_Field9 char(14)
 ,@Parm_Color9 integer
 ,@Parm_Titel10 char(30)
 ,@Parm_Field10 char(14)
 ,@Parm_Color10 integer
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_BelPosDisplay] SET
     [ZeilenId] = @Parm_ZeilenId
    ,[ZeilenNr] = @Parm_ZeilenNr
    ,[Summe] = @Parm_Summe
    ,[Titel] = @Parm_Titel
    ,[Paket] = @Parm_Paket
    ,[Leistung] = @Parm_Leistung
    ,[Zubehoer] = @Parm_Zubehoer
    ,[Titel1] = RTRIM(@Parm_Titel1)
    ,[Field1] = RTRIM(@Parm_Field1)
    ,[Color1] = @Parm_Color1
    ,[Titel2] = RTRIM(@Parm_Titel2)
    ,[Field2] = RTRIM(@Parm_Field2)
    ,[Color2] = @Parm_Color2
    ,[Titel3] = RTRIM(@Parm_Titel3)
    ,[Field3] = RTRIM(@Parm_Field3)
    ,[Color3] = @Parm_Color3
    ,[Titel4] = RTRIM(@Parm_Titel4)
    ,[Field4] = RTRIM(@Parm_Field4)
    ,[Color4] = @Parm_Color4
    ,[Titel5] = RTRIM(@Parm_Titel5)
    ,[Field5] = RTRIM(@Parm_Field5)
    ,[Color5] = @Parm_Color5
    ,[Titel6] = RTRIM(@Parm_Titel6)
    ,[Field6] = RTRIM(@Parm_Field6)
    ,[Color6] = @Parm_Color6
    ,[Titel7] = RTRIM(@Parm_Titel7)
    ,[Field7] = RTRIM(@Parm_Field7)
    ,[Color7] = @Parm_Color7
    ,[Titel8] = RTRIM(@Parm_Titel8)
    ,[Field8] = RTRIM(@Parm_Field8)
    ,[Color8] = @Parm_Color8
    ,[Titel9] = RTRIM(@Parm_Titel9)
    ,[Field9] = RTRIM(@Parm_Field9)
    ,[Color9] = @Parm_Color9
    ,[Titel10] = RTRIM(@Parm_Titel10)
    ,[Field10] = RTRIM(@Parm_Field10)
    ,[Color10] = @Parm_Color10
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Sel_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelPosDisplay]
  @RI integer
AS
SELECT
     [ZeilenId]
    ,[ZeilenNr]
    ,[Summe]
    ,[Titel]
    ,[Paket]
    ,[Leistung]
    ,[Zubehoer]
    ,[Titel1]
    ,[Field1]
    ,[Color1]
    ,[Titel2]
    ,[Field2]
    ,[Color2]
    ,[Titel3]
    ,[Field3]
    ,[Color3]
    ,[Titel4]
    ,[Field4]
    ,[Color4]
    ,[Titel5]
    ,[Field5]
    ,[Color5]
    ,[Titel6]
    ,[Field6]
    ,[Color6]
    ,[Titel7]
    ,[Field7]
    ,[Color7]
    ,[Titel8]
    ,[Field8]
    ,[Color8]
    ,[Titel9]
    ,[Field9]
    ,[Color9]
    ,[Titel10]
    ,[Field10]
    ,[Color10]
  FROM [dbo].[ut_BelPosDisplay]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Del_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Del_BelPosDisplay]
  @RI integer
AS
  DELETE FROM [dbo].[ut_BelPosDisplay] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Reorg_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelPosDisplay]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelPosDisplay] 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_BelPosDisplay] 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_BelPosDisplay] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_Append_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_Append_BelPosDisplay]
  @Parm_ZeilenId integer
 ,@Parm_ZeilenNr integer
 ,@Parm_Summe integer
 ,@Parm_Titel integer
 ,@Parm_Paket integer
 ,@Parm_Leistung integer
 ,@Parm_Zubehoer integer
 ,@Parm_Titel1 char(30)
 ,@Parm_Field1 char(14)
 ,@Parm_Color1 integer
 ,@Parm_Titel2 char(30)
 ,@Parm_Field2 char(14)
 ,@Parm_Color2 integer
 ,@Parm_Titel3 char(30)
 ,@Parm_Field3 char(14)
 ,@Parm_Color3 integer
 ,@Parm_Titel4 char(30)
 ,@Parm_Field4 char(14)
 ,@Parm_Color4 integer
 ,@Parm_Titel5 char(30)
 ,@Parm_Field5 char(14)
 ,@Parm_Color5 integer
 ,@Parm_Titel6 char(30)
 ,@Parm_Field6 char(14)
 ,@Parm_Color6 integer
 ,@Parm_Titel7 char(30)
 ,@Parm_Field7 char(14)
 ,@Parm_Color7 integer
 ,@Parm_Titel8 char(30)
 ,@Parm_Field8 char(14)
 ,@Parm_Color8 integer
 ,@Parm_Titel9 char(30)
 ,@Parm_Field9 char(14)
 ,@Parm_Color9 integer
 ,@Parm_Titel10 char(30)
 ,@Parm_Field10 char(14)
 ,@Parm_Color10 integer
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_BelPosDisplay])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelPosDisplay] (
    RecId
   ,[ZeilenId]
   ,[ZeilenNr]
   ,[Summe]
   ,[Titel]
   ,[Paket]
   ,[Leistung]
   ,[Zubehoer]
   ,[Titel1]
   ,[Field1]
   ,[Color1]
   ,[Titel2]
   ,[Field2]
   ,[Color2]
   ,[Titel3]
   ,[Field3]
   ,[Color3]
   ,[Titel4]
   ,[Field4]
   ,[Color4]
   ,[Titel5]
   ,[Field5]
   ,[Color5]
   ,[Titel6]
   ,[Field6]
   ,[Color6]
   ,[Titel7]
   ,[Field7]
   ,[Color7]
   ,[Titel8]
   ,[Field8]
   ,[Color8]
   ,[Titel9]
   ,[Field9]
   ,[Color9]
   ,[Titel10]
   ,[Field10]
   ,[Color10]
     ) VALUES (
    @NeueId
   ,@Parm_ZeilenId
   ,@Parm_ZeilenNr
   ,@Parm_Summe
   ,@Parm_Titel
   ,@Parm_Paket
   ,@Parm_Leistung
   ,@Parm_Zubehoer
   ,RTRIM(@Parm_Titel1)
   ,RTRIM(@Parm_Field1)
   ,@Parm_Color1
   ,RTRIM(@Parm_Titel2)
   ,RTRIM(@Parm_Field2)
   ,@Parm_Color2
   ,RTRIM(@Parm_Titel3)
   ,RTRIM(@Parm_Field3)
   ,@Parm_Color3
   ,RTRIM(@Parm_Titel4)
   ,RTRIM(@Parm_Field4)
   ,@Parm_Color4
   ,RTRIM(@Parm_Titel5)
   ,RTRIM(@Parm_Field5)
   ,@Parm_Color5
   ,RTRIM(@Parm_Titel6)
   ,RTRIM(@Parm_Field6)
   ,@Parm_Color6
   ,RTRIM(@Parm_Titel7)
   ,RTRIM(@Parm_Field7)
   ,@Parm_Color7
   ,RTRIM(@Parm_Titel8)
   ,RTRIM(@Parm_Field8)
   ,@Parm_Color8
   ,RTRIM(@Parm_Titel9)
   ,RTRIM(@Parm_Field9)
   ,@Parm_Color9
   ,RTRIM(@Parm_Titel10)
   ,RTRIM(@Parm_Field10)
   ,@Parm_Color10
       )
  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_BelPosDisplay')
  DROP PROCEDURE [dbo].[up_TrSel_BelPosDisplay]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelPosDisplay]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Titel1]))
      +LTRIM(RTRIM([Field1]))
      +LTRIM(RTRIM([Titel2]))
      +LTRIM(RTRIM([Field2]))
      +LTRIM(RTRIM([Titel3]))
      +LTRIM(RTRIM([Field3]))
      +LTRIM(RTRIM([Titel4]))
      +LTRIM(RTRIM([Field4]))
      +LTRIM(RTRIM([Titel5]))
      +LTRIM(RTRIM([Field5]))
      +LTRIM(RTRIM([Titel6]))
      +LTRIM(RTRIM([Field6]))
      +LTRIM(RTRIM([Titel7]))
      +LTRIM(RTRIM([Field7]))
      +LTRIM(RTRIM([Titel8]))
      +LTRIM(RTRIM([Field8]))
      +LTRIM(RTRIM([Titel9]))
      +LTRIM(RTRIM([Field9]))
      +LTRIM(RTRIM([Titel10]))
      +LTRIM(RTRIM([Field10]))
    AS Data
  FROM     [dbo].[ut_BelPosDisplay]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key00')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key01')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key02')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key03')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key03]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key04')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key04]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_BelPosDisplay_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_First_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_Last_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_Prior_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_Next_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_Next50_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_FindL_BelPosDisplay_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPosDisplay_Key05')
  DROP PROCEDURE [dbo].[up_FindF_BelPosDisplay_Key05]
GO

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

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

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

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

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

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

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

