------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_Bankenzuordnung')
BEGIN
CREATE TABLE [dbo].[ut_Bankenzuordnung]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[FibuKonto] char(8) DEFAULT ' '
  ,[BLZ] char(8) DEFAULT ' '
  ,[KontoNr] char(10) DEFAULT ' '
  ,[Bankname] char(30) DEFAULT ' '
  ,[SWIFT_BIC] char(11) DEFAULT ' '
  ,[IBAN] char(34) DEFAULT ' '
  CONSTRAINT [Pk_Bankenzuordnung]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Bankenzuordnung_KeyDel')
  DROP TRIGGER [dbo].[tr_Bankenzuordnung_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Bankenzuordnung_KeyUpd')
  DROP TRIGGER [dbo].[tr_Bankenzuordnung_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_Bankenzuordnung_Keys')
  DROP TABLE [dbo].[ut_Bankenzuordnung_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'FibuKonto')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [FibuKonto] 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_Bankenzuordnung' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [BLZ] 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_Bankenzuordnung' and sc.[name] = 'KontoNr')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [KontoNr] 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_Bankenzuordnung' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [Bankname] char(30) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'SWIFT_BIC')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [SWIFT_BIC] char(11) 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_Bankenzuordnung' and sc.[name] = 'IBAN')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ADD [IBAN] char(34) NOT NULL DEFAULT ' '
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'FibuKonto')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [FibuKonto] char(8)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [BLZ] char(8)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'KontoNr')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [KontoNr] char(10)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [Bankname] char(30)
END
GO
IF 11 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'SWIFT_BIC')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [SWIFT_BIC] char(11)
END
GO
IF 34 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankenzuordnung' and sc.[name] = 'IBAN')
BEGIN
  ALTER TABLE [dbo].[ut_Bankenzuordnung] ALTER COLUMN [IBAN] char(34)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Bankenzuordnung')
  DROP VIEW [dbo].[Bankenzuordnung]
GO
CREATE VIEW [dbo].[Bankenzuordnung] AS
  SELECT * FROM [dbo].[ut_Bankenzuordnung]
GO
CREATE TABLE [dbo].[ut_Bankenzuordnung_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[KEY00_Value] CHAR(18) NOT NULL
  ,[KEY01_Value] CHAR(18) NOT NULL
  ,[KEY02_Value] CHAR(21) NOT NULL
  CONSTRAINT [Pk_ut_Bankenzuordnung_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_Bankenzuordnung_KeyDel] ON [dbo].[ut_Bankenzuordnung]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_Bankenzuordnung_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_Bankenzuordnung_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[KEY00_Value],[KEY01_Value],[KEY02_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(8),[FibuKonto])+STR(RecId,10))
     ,UPPER(convert(char(8),[BLZ])+STR(RecId,10))
     ,UPPER(convert(char(11),[SWIFT_BIC])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_Bankenzuordnung_Keys] WITH (SERIALIZABLE) SET
    [KEY00_Value] = UPPER(convert(char(8),[FibuKonto])+STR([RecId],10))
   ,[KEY01_Value] = UPPER(convert(char(8),[BLZ])+STR([RecId],10))
   ,[KEY02_Value] = UPPER(convert(char(11),[SWIFT_BIC])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Add_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Add_Bankenzuordnung] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_Bankenzuordnung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Bankenzuordnung] (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_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Upd_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Upd_Bankenzuordnung]
  @RI integer
 ,@Parm_FibuKonto char(8)
 ,@Parm_BLZ char(8)
 ,@Parm_KontoNr char(10)
 ,@Parm_Bankname char(30)
 ,@Parm_SWIFT_BIC char(11)
 ,@Parm_IBAN char(34)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_Bankenzuordnung] SET
     [FibuKonto] = RTRIM(@Parm_FibuKonto)
    ,[BLZ] = RTRIM(@Parm_BLZ)
    ,[KontoNr] = RTRIM(@Parm_KontoNr)
    ,[Bankname] = RTRIM(@Parm_Bankname)
    ,[SWIFT_BIC] = RTRIM(@Parm_SWIFT_BIC)
    ,[IBAN] = RTRIM(@Parm_IBAN)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Sel_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Sel_Bankenzuordnung]
  @RI integer
AS
SELECT
     [FibuKonto]
    ,[BLZ]
    ,[KontoNr]
    ,[Bankname]
    ,[SWIFT_BIC]
    ,[IBAN]
  FROM [dbo].[ut_Bankenzuordnung]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Del_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Del_Bankenzuordnung]
  @RI integer
AS
  DELETE FROM [dbo].[ut_Bankenzuordnung] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Reorg_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Reorg_Bankenzuordnung]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_Bankenzuordnung] 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_Bankenzuordnung] 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_Bankenzuordnung] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_Append_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_Append_Bankenzuordnung]
  @Parm_FibuKonto char(8)
 ,@Parm_BLZ char(8)
 ,@Parm_KontoNr char(10)
 ,@Parm_Bankname char(30)
 ,@Parm_SWIFT_BIC char(11)
 ,@Parm_IBAN char(34)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_Bankenzuordnung])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Bankenzuordnung] (
    RecId
   ,[FibuKonto]
   ,[BLZ]
   ,[KontoNr]
   ,[Bankname]
   ,[SWIFT_BIC]
   ,[IBAN]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_FibuKonto)
   ,RTRIM(@Parm_BLZ)
   ,RTRIM(@Parm_KontoNr)
   ,RTRIM(@Parm_Bankname)
   ,RTRIM(@Parm_SWIFT_BIC)
   ,RTRIM(@Parm_IBAN)
       )
  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_Bankenzuordnung')
  DROP PROCEDURE [dbo].[up_TrSel_Bankenzuordnung]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Bankenzuordnung]
AS
  SELECT   RecId,
      LTRIM(RTRIM([FibuKonto]))
      +LTRIM(RTRIM([BLZ]))
      +LTRIM(RTRIM([KontoNr]))
      +LTRIM(RTRIM([Bankname]))
      +LTRIM(RTRIM([SWIFT_BIC]))
      +LTRIM(RTRIM([IBAN]))
    AS Data
  FROM     [dbo].[ut_Bankenzuordnung]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_KEY00] ON [dbo].[ut_Bankenzuordnung_Keys]
( [KEY00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_Prior_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_Prior50_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_FindL_Bankenzuordnung_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankenzuordnung_KEY00')
  DROP PROCEDURE [dbo].[up_FindF_Bankenzuordnung_KEY00]
GO

CREATE PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY00_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY00_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY00] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY00_Value] > (SELECT [KEY00_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY00_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY00] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY00_Value] > (SELECT [KEY00_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY00_Value]
GO

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

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

CREATE INDEX [Ik_KEY01] ON [dbo].[ut_Bankenzuordnung_Keys]
( [KEY01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_Prior_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_Prior50_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_FindL_Bankenzuordnung_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankenzuordnung_KEY01')
  DROP PROCEDURE [dbo].[up_FindF_Bankenzuordnung_KEY01]
GO

CREATE PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY01_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY01_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY01] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY01_Value] > (SELECT [KEY01_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY01_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY01_Value] > (SELECT [KEY01_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY01_Value]
GO

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

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

CREATE INDEX [Ik_KEY02] ON [dbo].[ut_Bankenzuordnung_Keys]
( [KEY02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_Prior_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_Prior50_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_FindL_Bankenzuordnung_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankenzuordnung_KEY02')
  DROP PROCEDURE [dbo].[up_FindF_Bankenzuordnung_KEY02]
GO

CREATE PROCEDURE [dbo].[up_First_Bankenzuordnung_KEY02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY02_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_Bankenzuordnung_KEY02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys] ORDER BY [KEY02_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_Bankenzuordnung_KEY02] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY02_Value] > (SELECT [KEY02_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY02_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_Bankenzuordnung_KEY02] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_Bankenzuordnung_Keys]
  WHERE [KEY02_Value] > (SELECT [KEY02_Value] FROM [dbo].[ut_Bankenzuordnung_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY02_Value]
GO

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

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

