------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_MareonFPAPos')
BEGIN
CREATE TABLE [dbo].[ut_MareonFPAPos]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[UNR] char(20) DEFAULT ' '
  ,[FPA] char(20) DEFAULT ' '
  ,[PosKey] char(20) DEFAULT ' '
  ,[Type] char(1) DEFAULT ' '
  ,[Price] float DEFAULT 0
  ,[DateFrom] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[DateTo] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Download] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Unit] char(6) DEFAULT ' '
  ,[ShortText] char(50) DEFAULT ' '
  ,[TextArt] integer DEFAULT 0
  ,[TextLkz] char(2) DEFAULT ' '
  ,[TextNr] char(18) DEFAULT ' '
  ,[HwpLkz] char(2) DEFAULT ' '
  ,[HwpArtnr] char(18) DEFAULT ' '
  ,[SubUNR] char(20) DEFAULT ' '
  ,[Region] integer DEFAULT 0
  ,[AutoArtikel] tinyint DEFAULT 0
  ,[disAutoArt] tinyint DEFAULT 0
  CONSTRAINT [Pk_MareonFPAPos]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonFPAPos_KeyDel')
  DROP TRIGGER [dbo].[tr_MareonFPAPos_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonFPAPos_KeyUpd')
  DROP TRIGGER [dbo].[tr_MareonFPAPos_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_MareonFPAPos_Keys')
  DROP TABLE [dbo].[ut_MareonFPAPos_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'UNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [UNR] 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_MareonFPAPos' and sc.[name] = 'FPA')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [FPA] 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_MareonFPAPos' and sc.[name] = 'PosKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [PosKey] 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_MareonFPAPos' and sc.[name] = 'Type')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [Type] char(1) 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_MareonFPAPos' and sc.[name] = 'Price')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [Price] float NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'DateFrom')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [DateFrom] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'DateTo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [DateTo] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'Download')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [Download] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'Unit')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [Unit] 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_MareonFPAPos' and sc.[name] = 'ShortText')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [ShortText] char(50) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'TextArt')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [TextArt] 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_MareonFPAPos' and sc.[name] = 'TextLkz')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [TextLkz] char(2) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'TextNr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [TextNr] char(18) 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_MareonFPAPos' and sc.[name] = 'HwpLkz')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [HwpLkz] char(2) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'HwpArtnr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [HwpArtnr] char(18) 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_MareonFPAPos' and sc.[name] = 'SubUNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [SubUNR] 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_MareonFPAPos' and sc.[name] = 'Region')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [Region] 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_MareonFPAPos' and sc.[name] = 'AutoArtikel')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [AutoArtikel] 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_MareonFPAPos' and sc.[name] = 'disAutoArt')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ADD [disAutoArt] tinyint NOT NULL DEFAULT 0
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'UNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [UNR] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'FPA')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [FPA] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'PosKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [PosKey] char(20)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'Type')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [Type] char(1)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'Unit')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [Unit] char(6)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'ShortText')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [ShortText] char(50)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'TextLkz')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [TextLkz] char(2)
END
GO
IF 18 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'TextNr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [TextNr] char(18)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'HwpLkz')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [HwpLkz] char(2)
END
GO
IF 18 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'HwpArtnr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [HwpArtnr] char(18)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonFPAPos' and sc.[name] = 'SubUNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonFPAPos] ALTER COLUMN [SubUNR] char(20)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'MareonFPAPos')
  DROP VIEW [dbo].[MareonFPAPos]
GO
CREATE VIEW [dbo].[MareonFPAPos] AS
  SELECT * FROM [dbo].[ut_MareonFPAPos]
GO
CREATE TABLE [dbo].[ut_MareonFPAPos_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(90) NOT NULL
  ,[Key01_Value] CHAR(90) NOT NULL
  ,[Key02_Value] CHAR(71) NOT NULL
  ,[Key03_Value] CHAR(120) NOT NULL
  ,[Key04_Value] CHAR(100) NOT NULL
  ,[Key05_Value] CHAR(50) NOT NULL
  CONSTRAINT [Pk_ut_MareonFPAPos_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_MareonFPAPos_KeyDel] ON [dbo].[ut_MareonFPAPos]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_MareonFPAPos_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_MareonFPAPos_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[FPA])+convert(char(20),[PosKey])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[PosKey])+convert(char(20),[FPA])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(1),[Type])+convert(char(20),[FPA])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[FPA])+convert(char(50),[ShortText])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(50),[ShortText])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+convert(char(2),[HwpLkz])+convert(char(18),[HwpArtnr])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_MareonFPAPos_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[FPA])+convert(char(20),[PosKey])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[PosKey])+convert(char(20),[FPA])+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(1),[Type])+convert(char(20),[FPA])+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(20),[FPA])+convert(char(50),[ShortText])+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(20),[UNR])+convert(char(20),[SubUNR])+convert(char(50),[ShortText])+STR([RecId],10))
   ,[Key05_Value] = UPPER(convert(char(20),[UNR])+convert(char(2),[HwpLkz])+convert(char(18),[HwpArtnr])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Add_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Add_MareonFPAPos] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_MareonFPAPos])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonFPAPos] (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_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Upd_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Upd_MareonFPAPos]
  @RI integer
 ,@Parm_UNR char(20)
 ,@Parm_FPA char(20)
 ,@Parm_PosKey char(20)
 ,@Parm_Type char(1)
 ,@Parm_Price float
 ,@Parm_DateFrom datetime
 ,@Parm_DateTo datetime
 ,@Parm_Download datetime
 ,@Parm_Unit char(6)
 ,@Parm_ShortText char(50)
 ,@Parm_TextArt integer
 ,@Parm_TextLkz char(2)
 ,@Parm_TextNr char(18)
 ,@Parm_HwpLkz char(2)
 ,@Parm_HwpArtnr char(18)
 ,@Parm_SubUNR char(20)
 ,@Parm_Region integer
 ,@Parm_AutoArtikel tinyint
 ,@Parm_disAutoArt tinyint
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_MareonFPAPos] SET
     [UNR] = RTRIM(@Parm_UNR)
    ,[FPA] = RTRIM(@Parm_FPA)
    ,[PosKey] = RTRIM(@Parm_PosKey)
    ,[Type] = RTRIM(@Parm_Type)
    ,[Price] = @Parm_Price
    ,[DateFrom] = @Parm_DateFrom
    ,[DateTo] = @Parm_DateTo
    ,[Download] = @Parm_Download
    ,[Unit] = RTRIM(@Parm_Unit)
    ,[ShortText] = RTRIM(@Parm_ShortText)
    ,[TextArt] = @Parm_TextArt
    ,[TextLkz] = RTRIM(@Parm_TextLkz)
    ,[TextNr] = RTRIM(@Parm_TextNr)
    ,[HwpLkz] = RTRIM(@Parm_HwpLkz)
    ,[HwpArtnr] = RTRIM(@Parm_HwpArtnr)
    ,[SubUNR] = RTRIM(@Parm_SubUNR)
    ,[Region] = @Parm_Region
    ,[AutoArtikel] = @Parm_AutoArtikel
    ,[disAutoArt] = @Parm_disAutoArt
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Sel_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Sel_MareonFPAPos]
  @RI integer
AS
SELECT
     [UNR]
    ,[FPA]
    ,[PosKey]
    ,[Type]
    ,[Price]
    ,[DateFrom]
    ,[DateTo]
    ,[Download]
    ,[Unit]
    ,[ShortText]
    ,[TextArt]
    ,[TextLkz]
    ,[TextNr]
    ,[HwpLkz]
    ,[HwpArtnr]
    ,[SubUNR]
    ,[Region]
    ,[AutoArtikel]
    ,[disAutoArt]
  FROM [dbo].[ut_MareonFPAPos]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Del_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Del_MareonFPAPos]
  @RI integer
AS
  DELETE FROM [dbo].[ut_MareonFPAPos] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Reorg_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Reorg_MareonFPAPos]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_MareonFPAPos] 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_MareonFPAPos] 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_MareonFPAPos] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_Append_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_Append_MareonFPAPos]
  @Parm_UNR char(20)
 ,@Parm_FPA char(20)
 ,@Parm_PosKey char(20)
 ,@Parm_Type char(1)
 ,@Parm_Price float
 ,@Parm_DateFrom datetime
 ,@Parm_DateTo datetime
 ,@Parm_Download datetime
 ,@Parm_Unit char(6)
 ,@Parm_ShortText char(50)
 ,@Parm_TextArt integer
 ,@Parm_TextLkz char(2)
 ,@Parm_TextNr char(18)
 ,@Parm_HwpLkz char(2)
 ,@Parm_HwpArtnr char(18)
 ,@Parm_SubUNR char(20)
 ,@Parm_Region integer
 ,@Parm_AutoArtikel tinyint
 ,@Parm_disAutoArt tinyint
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_MareonFPAPos])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonFPAPos] (
    RecId
   ,[UNR]
   ,[FPA]
   ,[PosKey]
   ,[Type]
   ,[Price]
   ,[DateFrom]
   ,[DateTo]
   ,[Download]
   ,[Unit]
   ,[ShortText]
   ,[TextArt]
   ,[TextLkz]
   ,[TextNr]
   ,[HwpLkz]
   ,[HwpArtnr]
   ,[SubUNR]
   ,[Region]
   ,[AutoArtikel]
   ,[disAutoArt]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_UNR)
   ,RTRIM(@Parm_FPA)
   ,RTRIM(@Parm_PosKey)
   ,RTRIM(@Parm_Type)
   ,@Parm_Price
   ,@Parm_DateFrom
   ,@Parm_DateTo
   ,@Parm_Download
   ,RTRIM(@Parm_Unit)
   ,RTRIM(@Parm_ShortText)
   ,@Parm_TextArt
   ,RTRIM(@Parm_TextLkz)
   ,RTRIM(@Parm_TextNr)
   ,RTRIM(@Parm_HwpLkz)
   ,RTRIM(@Parm_HwpArtnr)
   ,RTRIM(@Parm_SubUNR)
   ,@Parm_Region
   ,@Parm_AutoArtikel
   ,@Parm_disAutoArt
       )
  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_MareonFPAPos')
  DROP PROCEDURE [dbo].[up_TrSel_MareonFPAPos]
GO
CREATE PROCEDURE [dbo].[up_TrSel_MareonFPAPos]
AS
  SELECT   RecId,
      LTRIM(RTRIM([UNR]))
      +LTRIM(RTRIM([FPA]))
      +LTRIM(RTRIM([PosKey]))
      +LTRIM(RTRIM([Type]))
      +LTRIM(RTRIM([Unit]))
      +LTRIM(RTRIM([ShortText]))
      +LTRIM(RTRIM([TextLkz]))
      +LTRIM(RTRIM([TextNr]))
      +LTRIM(RTRIM([HwpLkz]))
      +LTRIM(RTRIM([HwpArtnr]))
      +LTRIM(RTRIM([SubUNR]))
    AS Data
  FROM     [dbo].[ut_MareonFPAPos]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key00')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key01')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key02')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key03')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key03]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key04')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key04]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_MareonFPAPos_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_First_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_Last_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_Prior_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_Next_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_Next50_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_FindL_MareonFPAPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonFPAPos_Key05')
  DROP PROCEDURE [dbo].[up_FindF_MareonFPAPos_Key05]
GO

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

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

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

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

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

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

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

