------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_Bankleitzahlen')
BEGIN
CREATE TABLE [dbo].[ut_Bankleitzahlen]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[BLZ] char(8) DEFAULT ' '
  ,[Bankname] char(30) DEFAULT ' '
  ,[SWIFT_BIC] char(11) DEFAULT ' '
  ,[Bankbez] char(60) DEFAULT ' '
  ,[Plz] char(5) DEFAULT ' '
  ,[Ort] char(35) DEFAULT ' '
  ,[KzPz] char(2) DEFAULT ' '
  ,[Pan] char(5) DEFAULT ' '
  CONSTRAINT [Pk_Bankleitzahlen]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Bankleitzahlen_KeyDel')
  DROP TRIGGER [dbo].[tr_Bankleitzahlen_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Bankleitzahlen_KeyUpd')
  DROP TRIGGER [dbo].[tr_Bankleitzahlen_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_Bankleitzahlen_Keys')
  DROP TABLE [dbo].[ut_Bankleitzahlen_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] 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_Bankleitzahlen' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] 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_Bankleitzahlen' and sc.[name] = 'SWIFT_BIC')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] 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_Bankleitzahlen' and sc.[name] = 'Bankbez')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ADD [Bankbez] char(60) 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_Bankleitzahlen' and sc.[name] = 'Plz')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ADD [Plz] char(5) 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_Bankleitzahlen' and sc.[name] = 'Ort')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ADD [Ort] char(35) 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_Bankleitzahlen' and sc.[name] = 'KzPz')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ADD [KzPz] 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_Bankleitzahlen' and sc.[name] = 'Pan')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ADD [Pan] char(5) 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_Bankleitzahlen' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [BLZ] char(8)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] 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_Bankleitzahlen' and sc.[name] = 'SWIFT_BIC')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [SWIFT_BIC] char(11)
END
GO
IF 60 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'Bankbez')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [Bankbez] char(60)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'Plz')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [Plz] char(5)
END
GO
IF 35 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'Ort')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [Ort] char(35)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'KzPz')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [KzPz] char(2)
END
GO
IF 5 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_Bankleitzahlen' and sc.[name] = 'Pan')
BEGIN
  ALTER TABLE [dbo].[ut_Bankleitzahlen] ALTER COLUMN [Pan] char(5)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Bankleitzahlen')
  DROP VIEW [dbo].[Bankleitzahlen]
GO
CREATE VIEW [dbo].[Bankleitzahlen] AS
  SELECT * FROM [dbo].[ut_Bankleitzahlen]
GO
CREATE TABLE [dbo].[ut_Bankleitzahlen_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[KEY00_Value] CHAR(18) NOT NULL
  ,[KEY01_Value] CHAR(40) NOT NULL
  ,[KEY02_Value] CHAR(21) NOT NULL
  CONSTRAINT [Pk_ut_Bankleitzahlen_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_Bankleitzahlen_KeyDel] ON [dbo].[ut_Bankleitzahlen]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_Bankleitzahlen_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

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

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

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Add_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Add_Bankleitzahlen] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_Bankleitzahlen])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Bankleitzahlen] (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_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Upd_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Upd_Bankleitzahlen]
  @RI integer
 ,@Parm_BLZ char(8)
 ,@Parm_Bankname char(30)
 ,@Parm_SWIFT_BIC char(11)
 ,@Parm_Bankbez char(60)
 ,@Parm_Plz char(5)
 ,@Parm_Ort char(35)
 ,@Parm_KzPz char(2)
 ,@Parm_Pan char(5)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_Bankleitzahlen] SET
     [BLZ] = RTRIM(@Parm_BLZ)
    ,[Bankname] = RTRIM(@Parm_Bankname)
    ,[SWIFT_BIC] = RTRIM(@Parm_SWIFT_BIC)
    ,[Bankbez] = RTRIM(@Parm_Bankbez)
    ,[Plz] = RTRIM(@Parm_Plz)
    ,[Ort] = RTRIM(@Parm_Ort)
    ,[KzPz] = RTRIM(@Parm_KzPz)
    ,[Pan] = RTRIM(@Parm_Pan)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Sel_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Sel_Bankleitzahlen]
  @RI integer
AS
SELECT
     [BLZ]
    ,[Bankname]
    ,[SWIFT_BIC]
    ,[Bankbez]
    ,[Plz]
    ,[Ort]
    ,[KzPz]
    ,[Pan]
  FROM [dbo].[ut_Bankleitzahlen]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Del_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Del_Bankleitzahlen]
  @RI integer
AS
  DELETE FROM [dbo].[ut_Bankleitzahlen] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Reorg_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Reorg_Bankleitzahlen]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_Bankleitzahlen] 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_Bankleitzahlen] 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_Bankleitzahlen] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_Append_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_Append_Bankleitzahlen]
  @Parm_BLZ char(8)
 ,@Parm_Bankname char(30)
 ,@Parm_SWIFT_BIC char(11)
 ,@Parm_Bankbez char(60)
 ,@Parm_Plz char(5)
 ,@Parm_Ort char(35)
 ,@Parm_KzPz char(2)
 ,@Parm_Pan char(5)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_Bankleitzahlen])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_Bankleitzahlen] (
    RecId
   ,[BLZ]
   ,[Bankname]
   ,[SWIFT_BIC]
   ,[Bankbez]
   ,[Plz]
   ,[Ort]
   ,[KzPz]
   ,[Pan]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_BLZ)
   ,RTRIM(@Parm_Bankname)
   ,RTRIM(@Parm_SWIFT_BIC)
   ,RTRIM(@Parm_Bankbez)
   ,RTRIM(@Parm_Plz)
   ,RTRIM(@Parm_Ort)
   ,RTRIM(@Parm_KzPz)
   ,RTRIM(@Parm_Pan)
       )
  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_Bankleitzahlen')
  DROP PROCEDURE [dbo].[up_TrSel_Bankleitzahlen]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Bankleitzahlen]
AS
  SELECT   RecId,
      LTRIM(RTRIM([BLZ]))
      +LTRIM(RTRIM([Bankname]))
      +LTRIM(RTRIM([SWIFT_BIC]))
      +LTRIM(RTRIM([Bankbez]))
      +LTRIM(RTRIM([Plz]))
      +LTRIM(RTRIM([Ort]))
      +LTRIM(RTRIM([KzPz]))
      +LTRIM(RTRIM([Pan]))
    AS Data
  FROM     [dbo].[ut_Bankleitzahlen]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_KEY00] ON [dbo].[ut_Bankleitzahlen_Keys]
( [KEY00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_First_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_Last_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_Prior_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_Next_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_Prior50_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_Next50_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_FindL_Bankleitzahlen_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankleitzahlen_KEY00')
  DROP PROCEDURE [dbo].[up_FindF_Bankleitzahlen_KEY00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_KEY01] ON [dbo].[ut_Bankleitzahlen_Keys]
( [KEY01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_First_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_Last_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_Prior_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_Next_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_Prior50_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_Next50_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_FindL_Bankleitzahlen_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankleitzahlen_KEY01')
  DROP PROCEDURE [dbo].[up_FindF_Bankleitzahlen_KEY01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_KEY02] ON [dbo].[ut_Bankleitzahlen_Keys]
( [KEY02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_First_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_Last_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_Prior_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_Next_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_Prior50_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_Next50_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_FindL_Bankleitzahlen_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bankleitzahlen_KEY02')
  DROP PROCEDURE [dbo].[up_FindF_Bankleitzahlen_KEY02]
GO

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

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

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

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

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

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

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

