------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_ZahlBelege')
BEGIN
CREATE TABLE [dbo].[ut_ZahlBelege]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[BELART] char(2) DEFAULT ' '
  ,[BELNR] char(8) DEFAULT ' '
  ,[ADRESSNR] char(15) DEFAULT ' '
  ,[BELDATUM] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[PRJNR] char(8) DEFAULT ' '
  ,[Brutto] float DEFAULT 0
  ,[Netto] float DEFAULT 0
  ,[Mwst] float DEFAULT 0
  ,[MwstSatz] float DEFAULT 0
  ,[SkontoTage] integer DEFAULT 0
  ,[SkontoSatz] float DEFAULT 0
  ,[MahnPlan] char(2) DEFAULT ' '
  ,[MahnStufe] integer DEFAULT 0
  ,[Vorhaben] char(10) DEFAULT ' '
  ,[Betreff1] char(42) DEFAULT ' '
  ,[Name1] char(40) DEFAULT ' '
  ,[Waehrung] char(6) DEFAULT ' '
  ,[Eurokurs] float DEFAULT 0
  ,[BezahltSum] float DEFAULT 0
  ,[Faelligkeit] integer DEFAULT 0
  ,[FDatum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[SDatum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[Status] char(1) DEFAULT ' '
  ,[DebKonto] char(8) DEFAULT ' '
  CONSTRAINT [Pk_ZahlBelege]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZahlBelege_KeyDel')
  DROP TRIGGER [dbo].[tr_ZahlBelege_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_ZahlBelege_KeyUpd')
  DROP TRIGGER [dbo].[tr_ZahlBelege_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_ZahlBelege_Keys')
  DROP TABLE [dbo].[ut_ZahlBelege_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'BELART')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [BELART] 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_ZahlBelege' and sc.[name] = 'BELNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [BELNR] char(8) 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_ZahlBelege' and sc.[name] = 'ADRESSNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [ADRESSNR] char(15) 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_ZahlBelege' and sc.[name] = 'BELDATUM')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [BELDATUM] 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_ZahlBelege' and sc.[name] = 'PRJNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [PRJNR] char(8) 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_ZahlBelege' and sc.[name] = 'Brutto')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Brutto] 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_ZahlBelege' and sc.[name] = 'Netto')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Netto] 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_ZahlBelege' and sc.[name] = 'Mwst')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Mwst] 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_ZahlBelege' and sc.[name] = 'MwstSatz')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [MwstSatz] 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_ZahlBelege' and sc.[name] = 'SkontoTage')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [SkontoTage] 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_ZahlBelege' and sc.[name] = 'SkontoSatz')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [SkontoSatz] 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_ZahlBelege' and sc.[name] = 'MahnPlan')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [MahnPlan] 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_ZahlBelege' and sc.[name] = 'MahnStufe')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [MahnStufe] 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_ZahlBelege' and sc.[name] = 'Vorhaben')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Vorhaben] char(10) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Betreff1')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Betreff1] char(42) 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_ZahlBelege' and sc.[name] = 'Name1')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Name1] 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_ZahlBelege' and sc.[name] = 'Waehrung')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Waehrung] 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_ZahlBelege' and sc.[name] = 'Eurokurs')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Eurokurs] 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_ZahlBelege' and sc.[name] = 'BezahltSum')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [BezahltSum] 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_ZahlBelege' and sc.[name] = 'Faelligkeit')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Faelligkeit] 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_ZahlBelege' and sc.[name] = 'FDatum')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [FDatum] 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_ZahlBelege' and sc.[name] = 'SDatum')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [SDatum] 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_ZahlBelege' and sc.[name] = 'Status')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [Status] 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_ZahlBelege' and sc.[name] = 'DebKonto')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ADD [DebKonto] char(8) NOT NULL DEFAULT ' '
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'BELART')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [BELART] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'BELNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [BELNR] char(8)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'ADRESSNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [ADRESSNR] char(15)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'PRJNR')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [PRJNR] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'MahnPlan')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [MahnPlan] char(2)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Vorhaben')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [Vorhaben] char(10)
END
GO
IF 42 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Betreff1')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [Betreff1] char(42)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Name1')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [Name1] char(40)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Waehrung')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [Waehrung] char(6)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'Status')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [Status] char(1)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_ZahlBelege' and sc.[name] = 'DebKonto')
BEGIN
  ALTER TABLE [dbo].[ut_ZahlBelege] ALTER COLUMN [DebKonto] char(8)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'ZahlBelege')
  DROP VIEW [dbo].[ZahlBelege]
GO
CREATE VIEW [dbo].[ZahlBelege] AS
  SELECT * FROM [dbo].[ut_ZahlBelege]
GO
CREATE TABLE [dbo].[ut_ZahlBelege_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(28) NOT NULL
  ,[Key01_Value] CHAR(20) NOT NULL
  ,[Key02_Value] CHAR(34) NOT NULL
  ,[Key03_Value] CHAR(44) NOT NULL
  ,[Key04_Value] CHAR(44) NOT NULL
  ,[Key05_Value] CHAR(27) NOT NULL
  ,[Key06_Value] CHAR(19) NOT NULL
  ,[Key07_Value] CHAR(36) NOT NULL
  ,[Key08_Value] CHAR(51) NOT NULL
  ,[Key09_Value] CHAR(27) NOT NULL
  ,[Key10_Value] CHAR(21) NOT NULL
  ,[Key11_Value] CHAR(21) NOT NULL
  CONSTRAINT [Pk_ut_ZahlBelege_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_ZahlBelege_KeyDel] ON [dbo].[ut_ZahlBelege]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_ZahlBelege_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_ZahlBelege_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value],[Key06_Value],[Key07_Value],[Key08_Value],[Key09_Value],[Key10_Value],[Key11_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(8),[PRJNR])+convert(char(2),[BELART])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(2),[BELART])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(15),[ADRESSNR])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+CONVERT(char(10),[FDatum],120)+convert(char(8),[BELNR])+convert(char(15),[ADRESSNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+CONVERT(char(10),[SDatum],120)+convert(char(8),[BELNR])+convert(char(15),[ADRESSNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(8),[DebKonto])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+CONVERT(char(10),[BELDATUM],120)+convert(char(15),[ADRESSNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(40),[Name1])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(8),[PRJNR])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(2),[BELART])+convert(char(8),[BELNR])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+STR([MahnStufe],2,0)+convert(char(8),[BELNR])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_ZahlBelege_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(8),[PRJNR])+convert(char(2),[BELART])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(2),[BELART])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(1),[Status])+convert(char(15),[ADRESSNR])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(1),[Status])+CONVERT(char(10),[FDatum],120)+convert(char(8),[BELNR])+convert(char(15),[ADRESSNR])+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(1),[Status])+CONVERT(char(10),[SDatum],120)+convert(char(8),[BELNR])+convert(char(15),[ADRESSNR])+STR([RecId],10))
   ,[Key05_Value] = UPPER(convert(char(1),[Status])+convert(char(8),[DebKonto])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key06_Value] = UPPER(convert(char(1),[Status])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key07_Value] = UPPER(convert(char(1),[Status])+CONVERT(char(10),[BELDATUM],120)+convert(char(15),[ADRESSNR])+STR([RecId],10))
   ,[Key08_Value] = UPPER(convert(char(1),[Status])+convert(char(40),[Name1])+STR([RecId],10))
   ,[Key09_Value] = UPPER(convert(char(1),[Status])+convert(char(8),[PRJNR])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key10_Value] = UPPER(convert(char(1),[Status])+convert(char(2),[BELART])+convert(char(8),[BELNR])+STR([RecId],10))
   ,[Key11_Value] = UPPER(convert(char(1),[Status])+STR([MahnStufe],2,0)+convert(char(8),[BELNR])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Add_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Add_ZahlBelege] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_ZahlBelege])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_ZahlBelege] (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_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Upd_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Upd_ZahlBelege]
  @RI integer
 ,@Parm_BELART char(2)
 ,@Parm_BELNR char(8)
 ,@Parm_ADRESSNR char(15)
 ,@Parm_BELDATUM datetime
 ,@Parm_PRJNR char(8)
 ,@Parm_Brutto float
 ,@Parm_Netto float
 ,@Parm_Mwst float
 ,@Parm_MwstSatz float
 ,@Parm_SkontoTage integer
 ,@Parm_SkontoSatz float
 ,@Parm_MahnPlan char(2)
 ,@Parm_MahnStufe integer
 ,@Parm_Vorhaben char(10)
 ,@Parm_Betreff1 char(42)
 ,@Parm_Name1 char(40)
 ,@Parm_Waehrung char(6)
 ,@Parm_Eurokurs float
 ,@Parm_BezahltSum float
 ,@Parm_Faelligkeit integer
 ,@Parm_FDatum datetime
 ,@Parm_SDatum datetime
 ,@Parm_Status char(1)
 ,@Parm_DebKonto char(8)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_ZahlBelege] SET
     [BELART] = RTRIM(@Parm_BELART)
    ,[BELNR] = RTRIM(@Parm_BELNR)
    ,[ADRESSNR] = RTRIM(@Parm_ADRESSNR)
    ,[BELDATUM] = @Parm_BELDATUM
    ,[PRJNR] = RTRIM(@Parm_PRJNR)
    ,[Brutto] = @Parm_Brutto
    ,[Netto] = @Parm_Netto
    ,[Mwst] = @Parm_Mwst
    ,[MwstSatz] = @Parm_MwstSatz
    ,[SkontoTage] = @Parm_SkontoTage
    ,[SkontoSatz] = @Parm_SkontoSatz
    ,[MahnPlan] = RTRIM(@Parm_MahnPlan)
    ,[MahnStufe] = @Parm_MahnStufe
    ,[Vorhaben] = RTRIM(@Parm_Vorhaben)
    ,[Betreff1] = RTRIM(@Parm_Betreff1)
    ,[Name1] = RTRIM(@Parm_Name1)
    ,[Waehrung] = RTRIM(@Parm_Waehrung)
    ,[Eurokurs] = @Parm_Eurokurs
    ,[BezahltSum] = @Parm_BezahltSum
    ,[Faelligkeit] = @Parm_Faelligkeit
    ,[FDatum] = @Parm_FDatum
    ,[SDatum] = @Parm_SDatum
    ,[Status] = RTRIM(@Parm_Status)
    ,[DebKonto] = RTRIM(@Parm_DebKonto)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Sel_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Sel_ZahlBelege]
  @RI integer
AS
SELECT
     [BELART]
    ,[BELNR]
    ,[ADRESSNR]
    ,[BELDATUM]
    ,[PRJNR]
    ,[Brutto]
    ,[Netto]
    ,[Mwst]
    ,[MwstSatz]
    ,[SkontoTage]
    ,[SkontoSatz]
    ,[MahnPlan]
    ,[MahnStufe]
    ,[Vorhaben]
    ,[Betreff1]
    ,[Name1]
    ,[Waehrung]
    ,[Eurokurs]
    ,[BezahltSum]
    ,[Faelligkeit]
    ,[FDatum]
    ,[SDatum]
    ,[Status]
    ,[DebKonto]
  FROM [dbo].[ut_ZahlBelege]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Del_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Del_ZahlBelege]
  @RI integer
AS
  DELETE FROM [dbo].[ut_ZahlBelege] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Reorg_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Reorg_ZahlBelege]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_ZahlBelege] 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_ZahlBelege] 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_ZahlBelege] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_ZahlBelege')
  DROP PROCEDURE [dbo].[up_Append_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_Append_ZahlBelege]
  @Parm_BELART char(2)
 ,@Parm_BELNR char(8)
 ,@Parm_ADRESSNR char(15)
 ,@Parm_BELDATUM datetime
 ,@Parm_PRJNR char(8)
 ,@Parm_Brutto float
 ,@Parm_Netto float
 ,@Parm_Mwst float
 ,@Parm_MwstSatz float
 ,@Parm_SkontoTage integer
 ,@Parm_SkontoSatz float
 ,@Parm_MahnPlan char(2)
 ,@Parm_MahnStufe integer
 ,@Parm_Vorhaben char(10)
 ,@Parm_Betreff1 char(42)
 ,@Parm_Name1 char(40)
 ,@Parm_Waehrung char(6)
 ,@Parm_Eurokurs float
 ,@Parm_BezahltSum float
 ,@Parm_Faelligkeit integer
 ,@Parm_FDatum datetime
 ,@Parm_SDatum datetime
 ,@Parm_Status char(1)
 ,@Parm_DebKonto char(8)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_ZahlBelege])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_ZahlBelege] (
    RecId
   ,[BELART]
   ,[BELNR]
   ,[ADRESSNR]
   ,[BELDATUM]
   ,[PRJNR]
   ,[Brutto]
   ,[Netto]
   ,[Mwst]
   ,[MwstSatz]
   ,[SkontoTage]
   ,[SkontoSatz]
   ,[MahnPlan]
   ,[MahnStufe]
   ,[Vorhaben]
   ,[Betreff1]
   ,[Name1]
   ,[Waehrung]
   ,[Eurokurs]
   ,[BezahltSum]
   ,[Faelligkeit]
   ,[FDatum]
   ,[SDatum]
   ,[Status]
   ,[DebKonto]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_BELART)
   ,RTRIM(@Parm_BELNR)
   ,RTRIM(@Parm_ADRESSNR)
   ,@Parm_BELDATUM
   ,RTRIM(@Parm_PRJNR)
   ,@Parm_Brutto
   ,@Parm_Netto
   ,@Parm_Mwst
   ,@Parm_MwstSatz
   ,@Parm_SkontoTage
   ,@Parm_SkontoSatz
   ,RTRIM(@Parm_MahnPlan)
   ,@Parm_MahnStufe
   ,RTRIM(@Parm_Vorhaben)
   ,RTRIM(@Parm_Betreff1)
   ,RTRIM(@Parm_Name1)
   ,RTRIM(@Parm_Waehrung)
   ,@Parm_Eurokurs
   ,@Parm_BezahltSum
   ,@Parm_Faelligkeit
   ,@Parm_FDatum
   ,@Parm_SDatum
   ,RTRIM(@Parm_Status)
   ,RTRIM(@Parm_DebKonto)
       )
  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_ZahlBelege')
  DROP PROCEDURE [dbo].[up_TrSel_ZahlBelege]
GO
CREATE PROCEDURE [dbo].[up_TrSel_ZahlBelege]
AS
  SELECT   RecId,
      LTRIM(RTRIM([BELART]))
      +LTRIM(RTRIM([BELNR]))
      +LTRIM(RTRIM([ADRESSNR]))
      +LTRIM(RTRIM([PRJNR]))
      +LTRIM(RTRIM([MahnPlan]))
      +LTRIM(RTRIM([Vorhaben]))
      +LTRIM(RTRIM([Betreff1]))
      +LTRIM(RTRIM([Name1]))
      +LTRIM(RTRIM([Waehrung]))
      +LTRIM(RTRIM([Status]))
      +LTRIM(RTRIM([DebKonto]))
    AS Data
  FROM     [dbo].[ut_ZahlBelege]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_ZahlBelege_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key00')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_ZahlBelege_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key01')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_ZahlBelege_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key02')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_ZahlBelege_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key03')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key03]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_ZahlBelege_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key04')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key04]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_ZahlBelege_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key05')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key05]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key06] ON [dbo].[ut_ZahlBelege_Keys]
( [Key06_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key06')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key06]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key06_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key06_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key06] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key06] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

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

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

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

CREATE INDEX [Ik_Key07] ON [dbo].[ut_ZahlBelege_Keys]
( [Key07_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key07')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key07]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key07_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key07_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key07] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key07] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

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

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

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

CREATE INDEX [Ik_Key08] ON [dbo].[ut_ZahlBelege_Keys]
( [Key08_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key08')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key08]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key08_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key08_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key08] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key08] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

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

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

CREATE INDEX [Ik_Key09] ON [dbo].[ut_ZahlBelege_Keys]
( [Key09_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key09')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key09]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key09]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key09_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key09]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key09_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key09] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key09_Value] > (SELECT [Key09_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key09] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key09_Value] > (SELECT [Key09_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value]
GO

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

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

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

CREATE INDEX [Ik_Key10] ON [dbo].[ut_ZahlBelege_Keys]
( [Key10_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key10')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key10]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key10]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key10_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key10]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key10_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key10] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key10_Value] > (SELECT [Key10_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key10] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key10_Value] > (SELECT [Key10_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value]
GO

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

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

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

CREATE INDEX [Ik_Key11] ON [dbo].[ut_ZahlBelege_Keys]
( [Key11_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_First_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_Last_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_Prior_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_Next_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_Prior50_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_Next50_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_FindL_ZahlBelege_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_ZahlBelege_Key11')
  DROP PROCEDURE [dbo].[up_FindF_ZahlBelege_Key11]
GO

CREATE PROCEDURE [dbo].[up_First_ZahlBelege_Key11]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key11_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_ZahlBelege_Key11]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys] ORDER BY [Key11_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_ZahlBelege_Key11] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key11_Value] > (SELECT [Key11_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_ZahlBelege_Key11] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_ZahlBelege_Keys]
  WHERE [Key11_Value] > (SELECT [Key11_Value] FROM [dbo].[ut_ZahlBelege_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value]
GO

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

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

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

