------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_MareonJobPerson')
BEGIN
CREATE TABLE [dbo].[ut_MareonJobPerson]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[NrBsh] char(20) DEFAULT ' '
  ,[PosNr] integer DEFAULT 0
  ,[LfdNr] integer DEFAULT 0
  ,[Role] char(10) DEFAULT ' '
  ,[HostDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[PN] char(10) DEFAULT ' '
  ,[Name1] char(40) DEFAULT ' '
  ,[Name2] char(40) DEFAULT ' '
  ,[Street] char(40) DEFAULT ' '
  ,[Zip] char(8) DEFAULT ' '
  ,[City] char(40) DEFAULT ' '
  ,[Country] char(10) DEFAULT ' '
  ,[Phone] char(30) DEFAULT ' '
  ,[PhoneNight] char(30) DEFAULT ' '
  ,[PhoneMobil] char(30) DEFAULT ' '
  ,[Phone2] char(30) DEFAULT ' '
  ,[Floor] char(30) DEFAULT ' '
  ,[Location] char(50) DEFAULT ' '
  ,[EMail] char(80) DEFAULT ' '
  ,[HomePage] char(80) DEFAULT ' '
  ,[Fax] char(30) DEFAULT ' '
  CONSTRAINT [Pk_MareonJobPerson]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonJobPerson_KeyDel')
  DROP TRIGGER [dbo].[tr_MareonJobPerson_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonJobPerson_KeyUpd')
  DROP TRIGGER [dbo].[tr_MareonJobPerson_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_MareonJobPerson_Keys')
  DROP TABLE [dbo].[ut_MareonJobPerson_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'NrBsh')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [NrBsh] 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_MareonJobPerson' and sc.[name] = 'PosNr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [PosNr] 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_MareonJobPerson' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [LfdNr] 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_MareonJobPerson' and sc.[name] = 'Role')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Role] 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_MareonJobPerson' and sc.[name] = 'HostDate')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [HostDate] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'PN')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [PN] 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_MareonJobPerson' and sc.[name] = 'Name1')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Name1] char(40) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Name2')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Name2] 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_MareonJobPerson' and sc.[name] = 'Street')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Street] 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_MareonJobPerson' and sc.[name] = 'Zip')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Zip] 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_MareonJobPerson' and sc.[name] = 'City')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [City] 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_MareonJobPerson' and sc.[name] = 'Country')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Country] 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_MareonJobPerson' and sc.[name] = 'Phone')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Phone] 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_MareonJobPerson' and sc.[name] = 'PhoneNight')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [PhoneNight] 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_MareonJobPerson' and sc.[name] = 'PhoneMobil')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [PhoneMobil] 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_MareonJobPerson' and sc.[name] = 'Phone2')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Phone2] 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_MareonJobPerson' and sc.[name] = 'Floor')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Floor] 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_MareonJobPerson' and sc.[name] = 'Location')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Location] char(50) 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_MareonJobPerson' and sc.[name] = 'EMail')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [EMail] char(80) 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_MareonJobPerson' and sc.[name] = 'HomePage')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [HomePage] char(80) 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_MareonJobPerson' and sc.[name] = 'Fax')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ADD [Fax] char(30) 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_MareonJobPerson' and sc.[name] = 'NrBsh')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [NrBsh] char(20)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Role')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Role] char(10)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'PN')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [PN] char(10)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Name1')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Name1] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Name2')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Name2] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Street')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Street] char(40)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Zip')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Zip] char(8)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'City')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [City] char(40)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Country')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Country] char(10)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Phone')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Phone] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'PhoneNight')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [PhoneNight] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'PhoneMobil')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [PhoneMobil] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Phone2')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Phone2] char(30)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Floor')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Floor] char(30)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Location')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Location] char(50)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'EMail')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [EMail] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'HomePage')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [HomePage] char(80)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobPerson' and sc.[name] = 'Fax')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobPerson] ALTER COLUMN [Fax] char(30)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'MareonJobPerson')
  DROP VIEW [dbo].[MareonJobPerson]
GO
CREATE VIEW [dbo].[MareonJobPerson] AS
  SELECT * FROM [dbo].[ut_MareonJobPerson]
GO
CREATE TABLE [dbo].[ut_MareonJobPerson_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(38) NOT NULL
  ,[Key01_Value] CHAR(48) NOT NULL
  CONSTRAINT [Pk_ut_MareonJobPerson_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_MareonJobPerson_KeyDel] ON [dbo].[ut_MareonJobPerson]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_MareonJobPerson_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_MareonJobPerson_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(20),[NrBsh])+STR([PosNr],4,0)+STR([LfdNr],4,0)+STR(RecId,10))
     ,UPPER(convert(char(20),[NrBsh])+STR([PosNr],4,0)+convert(char(10),[Role])+STR([LfdNr],4,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_MareonJobPerson_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(20),[NrBsh])+STR([PosNr],4,0)+STR([LfdNr],4,0)+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[NrBsh])+STR([PosNr],4,0)+convert(char(10),[Role])+STR([LfdNr],4,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Add_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Add_MareonJobPerson] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_MareonJobPerson])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonJobPerson] (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_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Upd_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Upd_MareonJobPerson]
  @RI integer
 ,@Parm_NrBsh char(20)
 ,@Parm_PosNr integer
 ,@Parm_LfdNr integer
 ,@Parm_Role char(10)
 ,@Parm_HostDate datetime
 ,@Parm_PN char(10)
 ,@Parm_Name1 char(40)
 ,@Parm_Name2 char(40)
 ,@Parm_Street char(40)
 ,@Parm_Zip char(8)
 ,@Parm_City char(40)
 ,@Parm_Country char(10)
 ,@Parm_Phone char(30)
 ,@Parm_PhoneNight char(30)
 ,@Parm_PhoneMobil char(30)
 ,@Parm_Phone2 char(30)
 ,@Parm_Floor char(30)
 ,@Parm_Location char(50)
 ,@Parm_EMail char(80)
 ,@Parm_HomePage char(80)
 ,@Parm_Fax char(30)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_MareonJobPerson] SET
     [NrBsh] = RTRIM(@Parm_NrBsh)
    ,[PosNr] = @Parm_PosNr
    ,[LfdNr] = @Parm_LfdNr
    ,[Role] = RTRIM(@Parm_Role)
    ,[HostDate] = @Parm_HostDate
    ,[PN] = RTRIM(@Parm_PN)
    ,[Name1] = RTRIM(@Parm_Name1)
    ,[Name2] = RTRIM(@Parm_Name2)
    ,[Street] = RTRIM(@Parm_Street)
    ,[Zip] = RTRIM(@Parm_Zip)
    ,[City] = RTRIM(@Parm_City)
    ,[Country] = RTRIM(@Parm_Country)
    ,[Phone] = RTRIM(@Parm_Phone)
    ,[PhoneNight] = RTRIM(@Parm_PhoneNight)
    ,[PhoneMobil] = RTRIM(@Parm_PhoneMobil)
    ,[Phone2] = RTRIM(@Parm_Phone2)
    ,[Floor] = RTRIM(@Parm_Floor)
    ,[Location] = RTRIM(@Parm_Location)
    ,[EMail] = RTRIM(@Parm_EMail)
    ,[HomePage] = RTRIM(@Parm_HomePage)
    ,[Fax] = RTRIM(@Parm_Fax)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Sel_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Sel_MareonJobPerson]
  @RI integer
AS
SELECT
     [NrBsh]
    ,[PosNr]
    ,[LfdNr]
    ,[Role]
    ,[HostDate]
    ,[PN]
    ,[Name1]
    ,[Name2]
    ,[Street]
    ,[Zip]
    ,[City]
    ,[Country]
    ,[Phone]
    ,[PhoneNight]
    ,[PhoneMobil]
    ,[Phone2]
    ,[Floor]
    ,[Location]
    ,[EMail]
    ,[HomePage]
    ,[Fax]
  FROM [dbo].[ut_MareonJobPerson]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Del_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Del_MareonJobPerson]
  @RI integer
AS
  DELETE FROM [dbo].[ut_MareonJobPerson] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Reorg_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Reorg_MareonJobPerson]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_MareonJobPerson] 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_MareonJobPerson] 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_MareonJobPerson] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_Append_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_Append_MareonJobPerson]
  @Parm_NrBsh char(20)
 ,@Parm_PosNr integer
 ,@Parm_LfdNr integer
 ,@Parm_Role char(10)
 ,@Parm_HostDate datetime
 ,@Parm_PN char(10)
 ,@Parm_Name1 char(40)
 ,@Parm_Name2 char(40)
 ,@Parm_Street char(40)
 ,@Parm_Zip char(8)
 ,@Parm_City char(40)
 ,@Parm_Country char(10)
 ,@Parm_Phone char(30)
 ,@Parm_PhoneNight char(30)
 ,@Parm_PhoneMobil char(30)
 ,@Parm_Phone2 char(30)
 ,@Parm_Floor char(30)
 ,@Parm_Location char(50)
 ,@Parm_EMail char(80)
 ,@Parm_HomePage char(80)
 ,@Parm_Fax char(30)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_MareonJobPerson])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonJobPerson] (
    RecId
   ,[NrBsh]
   ,[PosNr]
   ,[LfdNr]
   ,[Role]
   ,[HostDate]
   ,[PN]
   ,[Name1]
   ,[Name2]
   ,[Street]
   ,[Zip]
   ,[City]
   ,[Country]
   ,[Phone]
   ,[PhoneNight]
   ,[PhoneMobil]
   ,[Phone2]
   ,[Floor]
   ,[Location]
   ,[EMail]
   ,[HomePage]
   ,[Fax]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_NrBsh)
   ,@Parm_PosNr
   ,@Parm_LfdNr
   ,RTRIM(@Parm_Role)
   ,@Parm_HostDate
   ,RTRIM(@Parm_PN)
   ,RTRIM(@Parm_Name1)
   ,RTRIM(@Parm_Name2)
   ,RTRIM(@Parm_Street)
   ,RTRIM(@Parm_Zip)
   ,RTRIM(@Parm_City)
   ,RTRIM(@Parm_Country)
   ,RTRIM(@Parm_Phone)
   ,RTRIM(@Parm_PhoneNight)
   ,RTRIM(@Parm_PhoneMobil)
   ,RTRIM(@Parm_Phone2)
   ,RTRIM(@Parm_Floor)
   ,RTRIM(@Parm_Location)
   ,RTRIM(@Parm_EMail)
   ,RTRIM(@Parm_HomePage)
   ,RTRIM(@Parm_Fax)
       )
  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_MareonJobPerson')
  DROP PROCEDURE [dbo].[up_TrSel_MareonJobPerson]
GO
CREATE PROCEDURE [dbo].[up_TrSel_MareonJobPerson]
AS
  SELECT   RecId,
      LTRIM(RTRIM([NrBsh]))
      +LTRIM(RTRIM([Role]))
      +LTRIM(RTRIM([PN]))
      +LTRIM(RTRIM([Name1]))
      +LTRIM(RTRIM([Name2]))
      +LTRIM(RTRIM([Street]))
      +LTRIM(RTRIM([Zip]))
      +LTRIM(RTRIM([City]))
      +LTRIM(RTRIM([Country]))
      +LTRIM(RTRIM([Phone]))
      +LTRIM(RTRIM([PhoneNight]))
      +LTRIM(RTRIM([PhoneMobil]))
      +LTRIM(RTRIM([Phone2]))
      +LTRIM(RTRIM([Floor]))
      +LTRIM(RTRIM([Location]))
      +LTRIM(RTRIM([EMail]))
      +LTRIM(RTRIM([HomePage]))
      +LTRIM(RTRIM([Fax]))
    AS Data
  FROM     [dbo].[ut_MareonJobPerson]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_MareonJobPerson_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_First_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_Last_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_Next_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobPerson_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobPerson_Key00')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobPerson_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_MareonJobPerson_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_First_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_Last_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_Next_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobPerson_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobPerson_Key01')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobPerson_Key01]
GO

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

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

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

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

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

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

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

