------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_WartungsTypen')
BEGIN
CREATE TABLE [dbo].[ut_WartungsTypen]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Ident] integer DEFAULT 0
  ,[Nr] char(20) DEFAULT ' '
  ,[Bez1] char(40) DEFAULT ' '
  ,[Bez2] char(40) DEFAULT ' '
  ,[TextLkz] char(2) DEFAULT ' '
  ,[TextNr] char(18) DEFAULT ' '
  ,[Turnus] integer DEFAULT 0
  ,[PktAnlage] char(17) DEFAULT ' '
  ,[PktWartung] char(17) DEFAULT ' '
  ,[AdMuster] char(150) DEFAULT ' '
  CONSTRAINT [Pk_WartungsTypen]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_WartungsTypen_KeyDel')
  DROP TRIGGER [dbo].[tr_WartungsTypen_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_WartungsTypen_KeyUpd')
  DROP TRIGGER [dbo].[tr_WartungsTypen_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_WartungsTypen_Keys')
  DROP TABLE [dbo].[ut_WartungsTypen_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Ident')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [Ident] 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_WartungsTypen' and sc.[name] = 'Nr')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [Nr] char(20) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Bez1')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [Bez1] 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_WartungsTypen' and sc.[name] = 'Bez2')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [Bez2] 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_WartungsTypen' and sc.[name] = 'TextLkz')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [TextLkz] char(2) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'TextNr')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [TextNr] char(18) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Turnus')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [Turnus] 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_WartungsTypen' and sc.[name] = 'PktAnlage')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [PktAnlage] char(17) 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_WartungsTypen' and sc.[name] = 'PktWartung')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [PktWartung] char(17) 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_WartungsTypen' and sc.[name] = 'AdMuster')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ADD [AdMuster] char(150) NOT NULL DEFAULT ' '
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Nr')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [Nr] char(20)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Bez1')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [Bez1] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'Bez2')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [Bez2] char(40)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'TextLkz')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [TextLkz] char(2)
END
GO
IF 18 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'TextNr')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [TextNr] char(18)
END
GO
IF 17 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'PktAnlage')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [PktAnlage] char(17)
END
GO
IF 17 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'PktWartung')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [PktWartung] char(17)
END
GO
IF 150 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_WartungsTypen' and sc.[name] = 'AdMuster')
BEGIN
  ALTER TABLE [dbo].[ut_WartungsTypen] ALTER COLUMN [AdMuster] char(150)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'WartungsTypen')
  DROP VIEW [dbo].[WartungsTypen]
GO
CREATE VIEW [dbo].[WartungsTypen] AS
  SELECT * FROM [dbo].[ut_WartungsTypen]
GO
CREATE TABLE [dbo].[ut_WartungsTypen_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(18) NOT NULL
  ,[Key01_Value] CHAR(38) NOT NULL
  ,[Key02_Value] CHAR(72) NOT NULL
  ,[Key03_Value] CHAR(168) NOT NULL
  CONSTRAINT [Pk_ut_WartungsTypen_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_WartungsTypen_KeyDel] ON [dbo].[ut_WartungsTypen]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_WartungsTypen_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_WartungsTypen_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([Ident],8,0)+STR(RecId,10))
     ,UPPER(convert(char(20),[Nr])+STR([Ident],8,0)+STR(RecId,10))
     ,UPPER(convert(char(17),[PktAnlage])+convert(char(17),[PktWartung])+convert(char(20),[Nr])+STR([Ident],8,0)+STR(RecId,10))
     ,UPPER(convert(char(150),[AdMuster])+STR([Ident],8,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_WartungsTypen_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([Ident],8,0)+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[Nr])+STR([Ident],8,0)+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(17),[PktAnlage])+convert(char(17),[PktWartung])+convert(char(20),[Nr])+STR([Ident],8,0)+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(150),[AdMuster])+STR([Ident],8,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Add_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Add_WartungsTypen] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_WartungsTypen])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_WartungsTypen] (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_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Upd_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Upd_WartungsTypen]
  @RI integer
 ,@Parm_Ident integer
 ,@Parm_Nr char(20)
 ,@Parm_Bez1 char(40)
 ,@Parm_Bez2 char(40)
 ,@Parm_TextLkz char(2)
 ,@Parm_TextNr char(18)
 ,@Parm_Turnus integer
 ,@Parm_PktAnlage char(17)
 ,@Parm_PktWartung char(17)
 ,@Parm_AdMuster char(150)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_WartungsTypen] SET
     [Ident] = @Parm_Ident
    ,[Nr] = RTRIM(@Parm_Nr)
    ,[Bez1] = RTRIM(@Parm_Bez1)
    ,[Bez2] = RTRIM(@Parm_Bez2)
    ,[TextLkz] = RTRIM(@Parm_TextLkz)
    ,[TextNr] = RTRIM(@Parm_TextNr)
    ,[Turnus] = @Parm_Turnus
    ,[PktAnlage] = RTRIM(@Parm_PktAnlage)
    ,[PktWartung] = RTRIM(@Parm_PktWartung)
    ,[AdMuster] = RTRIM(@Parm_AdMuster)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Sel_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Sel_WartungsTypen]
  @RI integer
AS
SELECT
     [Ident]
    ,[Nr]
    ,[Bez1]
    ,[Bez2]
    ,[TextLkz]
    ,[TextNr]
    ,[Turnus]
    ,[PktAnlage]
    ,[PktWartung]
    ,[AdMuster]
  FROM [dbo].[ut_WartungsTypen]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Del_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Del_WartungsTypen]
  @RI integer
AS
  DELETE FROM [dbo].[ut_WartungsTypen] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Reorg_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Reorg_WartungsTypen]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_WartungsTypen] 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_WartungsTypen] 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_WartungsTypen] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_WartungsTypen')
  DROP PROCEDURE [dbo].[up_Append_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_Append_WartungsTypen]
  @Parm_Ident integer
 ,@Parm_Nr char(20)
 ,@Parm_Bez1 char(40)
 ,@Parm_Bez2 char(40)
 ,@Parm_TextLkz char(2)
 ,@Parm_TextNr char(18)
 ,@Parm_Turnus integer
 ,@Parm_PktAnlage char(17)
 ,@Parm_PktWartung char(17)
 ,@Parm_AdMuster char(150)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_WartungsTypen])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_WartungsTypen] (
    RecId
   ,[Ident]
   ,[Nr]
   ,[Bez1]
   ,[Bez2]
   ,[TextLkz]
   ,[TextNr]
   ,[Turnus]
   ,[PktAnlage]
   ,[PktWartung]
   ,[AdMuster]
     ) VALUES (
    @NeueId
   ,@Parm_Ident
   ,RTRIM(@Parm_Nr)
   ,RTRIM(@Parm_Bez1)
   ,RTRIM(@Parm_Bez2)
   ,RTRIM(@Parm_TextLkz)
   ,RTRIM(@Parm_TextNr)
   ,@Parm_Turnus
   ,RTRIM(@Parm_PktAnlage)
   ,RTRIM(@Parm_PktWartung)
   ,RTRIM(@Parm_AdMuster)
       )
  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_WartungsTypen')
  DROP PROCEDURE [dbo].[up_TrSel_WartungsTypen]
GO
CREATE PROCEDURE [dbo].[up_TrSel_WartungsTypen]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Nr]))
      +LTRIM(RTRIM([Bez1]))
      +LTRIM(RTRIM([Bez2]))
      +LTRIM(RTRIM([TextLkz]))
      +LTRIM(RTRIM([TextNr]))
      +LTRIM(RTRIM([PktAnlage]))
      +LTRIM(RTRIM([PktWartung]))
      +LTRIM(RTRIM([AdMuster]))
    AS Data
  FROM     [dbo].[ut_WartungsTypen]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_WartungsTypen_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_First_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_Last_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_Prior_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_Next_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_Next50_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_FindL_WartungsTypen_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_WartungsTypen_Key00')
  DROP PROCEDURE [dbo].[up_FindF_WartungsTypen_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_WartungsTypen_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_First_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_Last_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_Prior_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_Next_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_Next50_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_FindL_WartungsTypen_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_WartungsTypen_Key01')
  DROP PROCEDURE [dbo].[up_FindF_WartungsTypen_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_WartungsTypen_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_First_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_Last_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_Prior_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_Next_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_Next50_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_FindL_WartungsTypen_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_WartungsTypen_Key02')
  DROP PROCEDURE [dbo].[up_FindF_WartungsTypen_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_WartungsTypen_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_First_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_Last_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_Prior_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_Next_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_Next50_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_FindL_WartungsTypen_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_WartungsTypen_Key03')
  DROP PROCEDURE [dbo].[up_FindF_WartungsTypen_Key03]
GO

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

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

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

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

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

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

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

