------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelFormLineData')
BEGIN
CREATE TABLE [dbo].[ut_BelFormLineData]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[FormNr] integer DEFAULT 0
  ,[LfdNr] integer DEFAULT 0
  ,[SubNr] integer DEFAULT 0
  ,[GDI] char(4) DEFAULT ' '
  ,[Field] char(14) DEFAULT ' '
  ,[X] char(30) DEFAULT ' '
  ,[Y] char(30) DEFAULT ' '
  ,[CX] char(30) DEFAULT ' '
  ,[CY] char(30) DEFAULT ' '
  ,[R] integer DEFAULT 0
  ,[G] integer DEFAULT 0
  ,[B] integer DEFAULT 0
  ,[Style] integer DEFAULT 0
  ,[Size] integer DEFAULT 0
  ,[Font] char(40) DEFAULT ' '
  ,[Data] char(80) DEFAULT ' '
  ,[OnlyPV] tinyint DEFAULT 0
  ,[InputId] integer DEFAULT 0
  CONSTRAINT [Pk_BelFormLineData]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormLineData_KeyDel')
  DROP TRIGGER [dbo].[tr_BelFormLineData_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormLineData_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelFormLineData_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelFormLineData_Keys')
  DROP TABLE [dbo].[ut_BelFormLineData_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'FormNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] 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_BelFormLineData' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] 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_BelFormLineData' and sc.[name] = 'SubNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [SubNr] 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_BelFormLineData' and sc.[name] = 'GDI')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [GDI] 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_BelFormLineData' and sc.[name] = 'Field')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Field] 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_BelFormLineData' and sc.[name] = 'X')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [X] 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_BelFormLineData' and sc.[name] = 'Y')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Y] 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_BelFormLineData' and sc.[name] = 'CX')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [CX] 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_BelFormLineData' and sc.[name] = 'CY')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [CY] 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_BelFormLineData' and sc.[name] = 'R')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [R] 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_BelFormLineData' and sc.[name] = 'G')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [G] 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_BelFormLineData' and sc.[name] = 'B')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [B] 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_BelFormLineData' and sc.[name] = 'Style')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Style] 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_BelFormLineData' and sc.[name] = 'Size')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Size] 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_BelFormLineData' and sc.[name] = 'Font')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Font] 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_BelFormLineData' and sc.[name] = 'Data')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [Data] char(80) 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_BelFormLineData' and sc.[name] = 'OnlyPV')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [OnlyPV] 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_BelFormLineData' and sc.[name] = 'InputId')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ADD [InputId] integer NOT NULL DEFAULT 0
END
GO
IF 4 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'GDI')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [GDI] char(4)
END
GO
IF 14 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'Field')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [Field] char(14)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'X')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [X] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'Y')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [Y] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'CX')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [CX] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'CY')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [CY] char(30)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'Font')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [Font] char(40)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormLineData' and sc.[name] = 'Data')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormLineData] ALTER COLUMN [Data] char(80)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelFormLineData')
  DROP VIEW [dbo].[BelFormLineData]
GO
CREATE VIEW [dbo].[BelFormLineData] AS
  SELECT * FROM [dbo].[ut_BelFormLineData]
GO
CREATE TABLE [dbo].[ut_BelFormLineData_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(28) NOT NULL
  CONSTRAINT [Pk_ut_BelFormLineData_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_BelFormLineData_KeyDel] ON [dbo].[ut_BelFormLineData]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_BelFormLineData_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_BelFormLineData_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([FormNr],8,0)+STR([LfdNr],8,0)+STR([SubNr],2,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_BelFormLineData_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([FormNr],8,0)+STR([LfdNr],8,0)+STR([SubNr],2,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Add_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Add_BelFormLineData] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_BelFormLineData])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormLineData] (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_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Upd_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelFormLineData]
  @RI integer
 ,@Parm_FormNr integer
 ,@Parm_LfdNr integer
 ,@Parm_SubNr integer
 ,@Parm_GDI char(4)
 ,@Parm_Field char(14)
 ,@Parm_X char(30)
 ,@Parm_Y char(30)
 ,@Parm_CX char(30)
 ,@Parm_CY char(30)
 ,@Parm_R integer
 ,@Parm_G integer
 ,@Parm_B integer
 ,@Parm_Style integer
 ,@Parm_Size integer
 ,@Parm_Font char(40)
 ,@Parm_Data char(80)
 ,@Parm_OnlyPV tinyint
 ,@Parm_InputId integer
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_BelFormLineData] SET
     [FormNr] = @Parm_FormNr
    ,[LfdNr] = @Parm_LfdNr
    ,[SubNr] = @Parm_SubNr
    ,[GDI] = RTRIM(@Parm_GDI)
    ,[Field] = RTRIM(@Parm_Field)
    ,[X] = RTRIM(@Parm_X)
    ,[Y] = RTRIM(@Parm_Y)
    ,[CX] = RTRIM(@Parm_CX)
    ,[CY] = RTRIM(@Parm_CY)
    ,[R] = @Parm_R
    ,[G] = @Parm_G
    ,[B] = @Parm_B
    ,[Style] = @Parm_Style
    ,[Size] = @Parm_Size
    ,[Font] = RTRIM(@Parm_Font)
    ,[Data] = RTRIM(@Parm_Data)
    ,[OnlyPV] = @Parm_OnlyPV
    ,[InputId] = @Parm_InputId
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Sel_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelFormLineData]
  @RI integer
AS
SELECT
     [FormNr]
    ,[LfdNr]
    ,[SubNr]
    ,[GDI]
    ,[Field]
    ,[X]
    ,[Y]
    ,[CX]
    ,[CY]
    ,[R]
    ,[G]
    ,[B]
    ,[Style]
    ,[Size]
    ,[Font]
    ,[Data]
    ,[OnlyPV]
    ,[InputId]
  FROM [dbo].[ut_BelFormLineData]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Del_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Del_BelFormLineData]
  @RI integer
AS
  DELETE FROM [dbo].[ut_BelFormLineData] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Reorg_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelFormLineData]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelFormLineData] 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_BelFormLineData] 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_BelFormLineData] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelFormLineData')
  DROP PROCEDURE [dbo].[up_Append_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_Append_BelFormLineData]
  @Parm_FormNr integer
 ,@Parm_LfdNr integer
 ,@Parm_SubNr integer
 ,@Parm_GDI char(4)
 ,@Parm_Field char(14)
 ,@Parm_X char(30)
 ,@Parm_Y char(30)
 ,@Parm_CX char(30)
 ,@Parm_CY char(30)
 ,@Parm_R integer
 ,@Parm_G integer
 ,@Parm_B integer
 ,@Parm_Style integer
 ,@Parm_Size integer
 ,@Parm_Font char(40)
 ,@Parm_Data char(80)
 ,@Parm_OnlyPV tinyint
 ,@Parm_InputId integer
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_BelFormLineData])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormLineData] (
    RecId
   ,[FormNr]
   ,[LfdNr]
   ,[SubNr]
   ,[GDI]
   ,[Field]
   ,[X]
   ,[Y]
   ,[CX]
   ,[CY]
   ,[R]
   ,[G]
   ,[B]
   ,[Style]
   ,[Size]
   ,[Font]
   ,[Data]
   ,[OnlyPV]
   ,[InputId]
     ) VALUES (
    @NeueId
   ,@Parm_FormNr
   ,@Parm_LfdNr
   ,@Parm_SubNr
   ,RTRIM(@Parm_GDI)
   ,RTRIM(@Parm_Field)
   ,RTRIM(@Parm_X)
   ,RTRIM(@Parm_Y)
   ,RTRIM(@Parm_CX)
   ,RTRIM(@Parm_CY)
   ,@Parm_R
   ,@Parm_G
   ,@Parm_B
   ,@Parm_Style
   ,@Parm_Size
   ,RTRIM(@Parm_Font)
   ,RTRIM(@Parm_Data)
   ,@Parm_OnlyPV
   ,@Parm_InputId
       )
  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_BelFormLineData')
  DROP PROCEDURE [dbo].[up_TrSel_BelFormLineData]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelFormLineData]
AS
  SELECT   RecId,
      LTRIM(RTRIM([GDI]))
      +LTRIM(RTRIM([Field]))
      +LTRIM(RTRIM([X]))
      +LTRIM(RTRIM([Y]))
      +LTRIM(RTRIM([CX]))
      +LTRIM(RTRIM([CY]))
      +LTRIM(RTRIM([Font]))
      +LTRIM(RTRIM([Data]))
    AS Data
  FROM     [dbo].[ut_BelFormLineData]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_BelFormLineData_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_First_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_Last_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_Prior_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_Next_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_Next50_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_FindL_BelFormLineData_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormLineData_Key00')
  DROP PROCEDURE [dbo].[up_FindF_BelFormLineData_Key00]
GO

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

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

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

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

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

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

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

