------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_DTAUS')
BEGIN
CREATE TABLE [dbo].[ut_DTAUS]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[FibuKonto] char(8) DEFAULT ' '
  ,[LfdNr] char(8) DEFAULT ' '
  ,[Betrag] float DEFAULT 0
  ,[Waehr] char(6) DEFAULT ' '
  ,[Empfaenger] char(30) DEFAULT ' '
  ,[BLZ] char(8) DEFAULT ' '
  ,[KontoNr] char(10) DEFAULT ' '
  ,[Bankname] char(30) DEFAULT ' '
  ,[Zweck1] char(30) DEFAULT ' '
  ,[Zweck2] char(30) DEFAULT ' '
  ,[DestDebNr] char(15) DEFAULT ' '
  ,[Warten] tinyint DEFAULT 0
  ,[Vkz] integer DEFAULT 0
  ,[DateDone] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  CONSTRAINT [Pk_DTAUS]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_DTAUS_KeyDel')
  DROP TRIGGER [dbo].[tr_DTAUS_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_DTAUS_KeyUpd')
  DROP TRIGGER [dbo].[tr_DTAUS_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_DTAUS_Keys')
  DROP TABLE [dbo].[ut_DTAUS_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'FibuKonto')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [LfdNr] 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_DTAUS' and sc.[name] = 'Betrag')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Betrag] 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_DTAUS' and sc.[name] = 'Waehr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Waehr] 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_DTAUS' and sc.[name] = 'Empfaenger')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Empfaenger] 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_DTAUS' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'KontoNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'Zweck1')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Zweck1] 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_DTAUS' and sc.[name] = 'Zweck2')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Zweck2] 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_DTAUS' and sc.[name] = 'DestDebNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [DestDebNr] 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_DTAUS' and sc.[name] = 'Warten')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Warten] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'Vkz')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [Vkz] 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_DTAUS' and sc.[name] = 'DateDone')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ADD [DateDone] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'FibuKonto')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [LfdNr] char(8)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'Waehr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [Waehr] char(6)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'Empfaenger')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [Empfaenger] char(30)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'BLZ')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'KontoNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] 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_DTAUS' and sc.[name] = 'Bankname')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [Bankname] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'Zweck1')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [Zweck1] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'Zweck2')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [Zweck2] char(30)
END
GO
IF 15 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_DTAUS' and sc.[name] = 'DestDebNr')
BEGIN
  ALTER TABLE [dbo].[ut_DTAUS] ALTER COLUMN [DestDebNr] char(15)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'DTAUS')
  DROP VIEW [dbo].[DTAUS]
GO
CREATE VIEW [dbo].[DTAUS] AS
  SELECT * FROM [dbo].[ut_DTAUS]
GO
CREATE TABLE [dbo].[ut_DTAUS_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[KEY00_Value] CHAR(18) NOT NULL
  ,[KEY01_Value] CHAR(26) NOT NULL
  ,[KEY02_Value] CHAR(44) NOT NULL
  ,[KEY03_Value] CHAR(27) NOT NULL
  ,[KEY04_Value] CHAR(45) NOT NULL
  CONSTRAINT [Pk_ut_DTAUS_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_DTAUS_KeyDel] ON [dbo].[ut_DTAUS]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_DTAUS_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_DTAUS_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[KEY00_Value],[KEY01_Value],[KEY02_Value],[KEY03_Value],[KEY04_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(8),[LfdNr])+STR(RecId,10))
     ,UPPER(convert(char(8),[FibuKonto])+convert(char(8),[LfdNr])+STR(RecId,10))
     ,UPPER(convert(char(8),[FibuKonto])+convert(char(8),[BLZ])+convert(char(10),[KontoNr])+convert(char(8),[LfdNr])+STR(RecId,10))
     ,UPPER(STR([Vkz],1,0)+convert(char(8),[FibuKonto])+convert(char(8),[LfdNr])+STR(RecId,10))
     ,UPPER(STR([Vkz],1,0)+convert(char(8),[FibuKonto])+convert(char(8),[BLZ])+convert(char(10),[KontoNr])+convert(char(8),[LfdNr])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_DTAUS_Keys] WITH (SERIALIZABLE) SET
    [KEY00_Value] = UPPER(convert(char(8),[LfdNr])+STR([RecId],10))
   ,[KEY01_Value] = UPPER(convert(char(8),[FibuKonto])+convert(char(8),[LfdNr])+STR([RecId],10))
   ,[KEY02_Value] = UPPER(convert(char(8),[FibuKonto])+convert(char(8),[BLZ])+convert(char(10),[KontoNr])+convert(char(8),[LfdNr])+STR([RecId],10))
   ,[KEY03_Value] = UPPER(STR([Vkz],1,0)+convert(char(8),[FibuKonto])+convert(char(8),[LfdNr])+STR([RecId],10))
   ,[KEY04_Value] = UPPER(STR([Vkz],1,0)+convert(char(8),[FibuKonto])+convert(char(8),[BLZ])+convert(char(10),[KontoNr])+convert(char(8),[LfdNr])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_DTAUS')
  DROP PROCEDURE [dbo].[up_Add_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Add_DTAUS] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_DTAUS])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_DTAUS] (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_DTAUS')
  DROP PROCEDURE [dbo].[up_Upd_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Upd_DTAUS]
  @RI integer
 ,@Parm_FibuKonto char(8)
 ,@Parm_LfdNr char(8)
 ,@Parm_Betrag float
 ,@Parm_Waehr char(6)
 ,@Parm_Empfaenger char(30)
 ,@Parm_BLZ char(8)
 ,@Parm_KontoNr char(10)
 ,@Parm_Bankname char(30)
 ,@Parm_Zweck1 char(30)
 ,@Parm_Zweck2 char(30)
 ,@Parm_DestDebNr char(15)
 ,@Parm_Warten tinyint
 ,@Parm_Vkz integer
 ,@Parm_DateDone datetime
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_DTAUS] SET
     [FibuKonto] = RTRIM(@Parm_FibuKonto)
    ,[LfdNr] = RTRIM(@Parm_LfdNr)
    ,[Betrag] = @Parm_Betrag
    ,[Waehr] = RTRIM(@Parm_Waehr)
    ,[Empfaenger] = RTRIM(@Parm_Empfaenger)
    ,[BLZ] = RTRIM(@Parm_BLZ)
    ,[KontoNr] = RTRIM(@Parm_KontoNr)
    ,[Bankname] = RTRIM(@Parm_Bankname)
    ,[Zweck1] = RTRIM(@Parm_Zweck1)
    ,[Zweck2] = RTRIM(@Parm_Zweck2)
    ,[DestDebNr] = RTRIM(@Parm_DestDebNr)
    ,[Warten] = @Parm_Warten
    ,[Vkz] = @Parm_Vkz
    ,[DateDone] = @Parm_DateDone
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_DTAUS')
  DROP PROCEDURE [dbo].[up_Sel_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Sel_DTAUS]
  @RI integer
AS
SELECT
     [FibuKonto]
    ,[LfdNr]
    ,[Betrag]
    ,[Waehr]
    ,[Empfaenger]
    ,[BLZ]
    ,[KontoNr]
    ,[Bankname]
    ,[Zweck1]
    ,[Zweck2]
    ,[DestDebNr]
    ,[Warten]
    ,[Vkz]
    ,[DateDone]
  FROM [dbo].[ut_DTAUS]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_DTAUS')
  DROP PROCEDURE [dbo].[up_Del_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Del_DTAUS]
  @RI integer
AS
  DELETE FROM [dbo].[ut_DTAUS] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_DTAUS')
  DROP PROCEDURE [dbo].[up_Reorg_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Reorg_DTAUS]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_DTAUS] 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_DTAUS] 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_DTAUS] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_DTAUS')
  DROP PROCEDURE [dbo].[up_Append_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_Append_DTAUS]
  @Parm_FibuKonto char(8)
 ,@Parm_LfdNr char(8)
 ,@Parm_Betrag float
 ,@Parm_Waehr char(6)
 ,@Parm_Empfaenger char(30)
 ,@Parm_BLZ char(8)
 ,@Parm_KontoNr char(10)
 ,@Parm_Bankname char(30)
 ,@Parm_Zweck1 char(30)
 ,@Parm_Zweck2 char(30)
 ,@Parm_DestDebNr char(15)
 ,@Parm_Warten tinyint
 ,@Parm_Vkz integer
 ,@Parm_DateDone datetime
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_DTAUS])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_DTAUS] (
    RecId
   ,[FibuKonto]
   ,[LfdNr]
   ,[Betrag]
   ,[Waehr]
   ,[Empfaenger]
   ,[BLZ]
   ,[KontoNr]
   ,[Bankname]
   ,[Zweck1]
   ,[Zweck2]
   ,[DestDebNr]
   ,[Warten]
   ,[Vkz]
   ,[DateDone]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_FibuKonto)
   ,RTRIM(@Parm_LfdNr)
   ,@Parm_Betrag
   ,RTRIM(@Parm_Waehr)
   ,RTRIM(@Parm_Empfaenger)
   ,RTRIM(@Parm_BLZ)
   ,RTRIM(@Parm_KontoNr)
   ,RTRIM(@Parm_Bankname)
   ,RTRIM(@Parm_Zweck1)
   ,RTRIM(@Parm_Zweck2)
   ,RTRIM(@Parm_DestDebNr)
   ,@Parm_Warten
   ,@Parm_Vkz
   ,@Parm_DateDone
       )
  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_DTAUS')
  DROP PROCEDURE [dbo].[up_TrSel_DTAUS]
GO
CREATE PROCEDURE [dbo].[up_TrSel_DTAUS]
AS
  SELECT   RecId,
      LTRIM(RTRIM([FibuKonto]))
      +LTRIM(RTRIM([LfdNr]))
      +LTRIM(RTRIM([Waehr]))
      +LTRIM(RTRIM([Empfaenger]))
      +LTRIM(RTRIM([BLZ]))
      +LTRIM(RTRIM([KontoNr]))
      +LTRIM(RTRIM([Bankname]))
      +LTRIM(RTRIM([Zweck1]))
      +LTRIM(RTRIM([Zweck2]))
      +LTRIM(RTRIM([DestDebNr]))
    AS Data
  FROM     [dbo].[ut_DTAUS]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_KEY00] ON [dbo].[ut_DTAUS_Keys]
( [KEY00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_First_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_Last_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_Prior_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_Next_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_Prior50_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_Next50_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_FindL_DTAUS_KEY00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DTAUS_KEY00')
  DROP PROCEDURE [dbo].[up_FindF_DTAUS_KEY00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_KEY01] ON [dbo].[ut_DTAUS_Keys]
( [KEY01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_First_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_Last_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_Prior_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_Next_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_Prior50_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_Next50_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_FindL_DTAUS_KEY01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DTAUS_KEY01')
  DROP PROCEDURE [dbo].[up_FindF_DTAUS_KEY01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_KEY02] ON [dbo].[ut_DTAUS_Keys]
( [KEY02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_First_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_Last_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_Prior_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_Next_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_Prior50_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_Next50_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_FindL_DTAUS_KEY02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DTAUS_KEY02')
  DROP PROCEDURE [dbo].[up_FindF_DTAUS_KEY02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_KEY03] ON [dbo].[ut_DTAUS_Keys]
( [KEY03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_First_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_Last_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_Prior_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_Next_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_Prior50_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_Next50_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_FindL_DTAUS_KEY03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DTAUS_KEY03')
  DROP PROCEDURE [dbo].[up_FindF_DTAUS_KEY03]
GO

CREATE PROCEDURE [dbo].[up_First_DTAUS_KEY03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys] ORDER BY [KEY03_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_DTAUS_KEY03]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys] ORDER BY [KEY03_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_DTAUS_KEY03] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys]
  WHERE [KEY03_Value] > (SELECT [KEY03_Value] FROM [dbo].[ut_DTAUS_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY03_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_DTAUS_KEY03] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_DTAUS_Keys]
  WHERE [KEY03_Value] > (SELECT [KEY03_Value] FROM [dbo].[ut_DTAUS_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY03_Value]
GO

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

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

CREATE INDEX [Ik_KEY04] ON [dbo].[ut_DTAUS_Keys]
( [KEY04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_First_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_Last_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_Prior_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_Next_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_Prior50_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_Next50_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_FindL_DTAUS_KEY04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_DTAUS_KEY04')
  DROP PROCEDURE [dbo].[up_FindF_DTAUS_KEY04]
GO

CREATE PROCEDURE [dbo].[up_First_DTAUS_KEY04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys] ORDER BY [KEY04_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_DTAUS_KEY04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys] ORDER BY [KEY04_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_DTAUS_KEY04] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_DTAUS_Keys]
  WHERE [KEY04_Value] > (SELECT [KEY04_Value] FROM [dbo].[ut_DTAUS_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY04_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_DTAUS_KEY04] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_DTAUS_Keys]
  WHERE [KEY04_Value] > (SELECT [KEY04_Value] FROM [dbo].[ut_DTAUS_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [KEY04_Value]
GO

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

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

