------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_MareonJobs')
BEGIN
CREATE TABLE [dbo].[ut_MareonJobs]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[UNR] char(20) DEFAULT ' '
  ,[JobERP] char(30) DEFAULT ' '
  ,[HostDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[CraftsPN] char(10) DEFAULT ' '
  ,[Status] char(1) DEFAULT ' '
  ,[Datum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[WI] char(20) DEFAULT ' '
  ,[HS] char(20) DEFAULT ' '
  ,[ME] char(20) DEFAULT ' '
  ,[Type] char(2) DEFAULT ' '
  ,[JobPhoned] tinyint DEFAULT 0
  ,[Location] char(200) DEFAULT ' '
  ,[EP] char(20) DEFAULT ' '
  ,[Costs] float DEFAULT 0
  ,[TerminVon] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[ZeitVon] char(12) DEFAULT ' '
  ,[TerminBis] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[ZeitBis] char(12) DEFAULT ' '
  ,[TextId] integer DEFAULT 0
  ,[InstrId] integer DEFAULT 0
  ,[SubUNR] char(20) DEFAULT ' '
  ,[Warranty] tinyint DEFAULT 0
  ,[TodoFromJob] tinyint DEFAULT 0
  ,[MareonNo] char(20) DEFAULT ' '
  ,[Modify] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[DisplayNo] char(30) DEFAULT ' '
  ,[Insurance] tinyint DEFAULT 0
  ,[dateWithTe] tinyint DEFAULT 0
  ,[tradeKey] char(20) DEFAULT ' '
  ,[trade] char(50) DEFAULT ' '
  ,[Description] char(50) DEFAULT ' '
  ,[measureSvc] tinyint DEFAULT 0
  ,[msOrderType] char(20) DEFAULT ' '
  ,[msIdentKey] char(20) DEFAULT ' '
  ,[msIventKey] char(20) DEFAULT ' '
  ,[msDescr] char(50) DEFAULT ' '
  ,[NrBsh] char(20) DEFAULT ' '
  ,[Woche] integer DEFAULT 0
  ,[Barcode] char(50) DEFAULT ' '
  ,[CancelRs] char(80) DEFAULT ' '
  ,[EStG35a] integer DEFAULT 0
  ,[OfferDate] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[OfferNo] char(20) DEFAULT ' '
  ,[OfferPrice] float DEFAULT 0
  ,[FPA] tinyint DEFAULT 0
  ,[FremdVerw] tinyint DEFAULT 0
  ,[GrossAuftr] tinyint DEFAULT 0
  ,[TypeValue] char(20) DEFAULT ' '
  CONSTRAINT [Pk_MareonJobs]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonJobs_KeyDel')
  DROP TRIGGER [dbo].[tr_MareonJobs_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_MareonJobs_KeyUpd')
  DROP TRIGGER [dbo].[tr_MareonJobs_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_MareonJobs_Keys')
  DROP TABLE [dbo].[ut_MareonJobs_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'UNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [UNR] 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_MareonJobs' and sc.[name] = 'JobERP')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [JobERP] 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_MareonJobs' and sc.[name] = 'HostDate')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] 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_MareonJobs' and sc.[name] = 'CraftsPN')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [CraftsPN] 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_MareonJobs' and sc.[name] = 'Status')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Status] char(1) 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_MareonJobs' and sc.[name] = 'Datum')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Datum] 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_MareonJobs' and sc.[name] = 'WI')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [WI] 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_MareonJobs' and sc.[name] = 'HS')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [HS] 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_MareonJobs' and sc.[name] = 'ME')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [ME] 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_MareonJobs' and sc.[name] = 'Type')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Type] 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_MareonJobs' and sc.[name] = 'JobPhoned')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [JobPhoned] 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_MareonJobs' and sc.[name] = 'Location')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Location] char(200) 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_MareonJobs' and sc.[name] = 'EP')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [EP] 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_MareonJobs' and sc.[name] = 'Costs')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Costs] 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_MareonJobs' and sc.[name] = 'TerminVon')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [TerminVon] 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_MareonJobs' and sc.[name] = 'ZeitVon')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [ZeitVon] char(12) 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_MareonJobs' and sc.[name] = 'TerminBis')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [TerminBis] 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_MareonJobs' and sc.[name] = 'ZeitBis')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [ZeitBis] char(12) 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_MareonJobs' and sc.[name] = 'TextId')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [TextId] 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_MareonJobs' and sc.[name] = 'InstrId')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [InstrId] 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_MareonJobs' and sc.[name] = 'SubUNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [SubUNR] 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_MareonJobs' and sc.[name] = 'Warranty')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Warranty] 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_MareonJobs' and sc.[name] = 'TodoFromJob')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [TodoFromJob] 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_MareonJobs' and sc.[name] = 'MareonNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [MareonNo] 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_MareonJobs' and sc.[name] = 'Modify')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Modify] 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_MareonJobs' and sc.[name] = 'DisplayNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [DisplayNo] 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_MareonJobs' and sc.[name] = 'Insurance')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Insurance] 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_MareonJobs' and sc.[name] = 'dateWithTe')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [dateWithTe] 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_MareonJobs' and sc.[name] = 'tradeKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [tradeKey] 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_MareonJobs' and sc.[name] = 'trade')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [trade] 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_MareonJobs' and sc.[name] = 'Description')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Description] 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_MareonJobs' and sc.[name] = 'measureSvc')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [measureSvc] 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_MareonJobs' and sc.[name] = 'msOrderType')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [msOrderType] 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_MareonJobs' and sc.[name] = 'msIdentKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [msIdentKey] 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_MareonJobs' and sc.[name] = 'msIventKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [msIventKey] 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_MareonJobs' and sc.[name] = 'msDescr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [msDescr] 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_MareonJobs' and sc.[name] = 'NrBsh')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] 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_MareonJobs' and sc.[name] = 'Woche')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Woche] 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_MareonJobs' and sc.[name] = 'Barcode')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [Barcode] 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_MareonJobs' and sc.[name] = 'CancelRs')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [CancelRs] 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_MareonJobs' and sc.[name] = 'EStG35a')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [EStG35a] 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_MareonJobs' and sc.[name] = 'OfferDate')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [OfferDate] 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_MareonJobs' and sc.[name] = 'OfferNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [OfferNo] 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_MareonJobs' and sc.[name] = 'OfferPrice')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [OfferPrice] 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_MareonJobs' and sc.[name] = 'FPA')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [FPA] 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_MareonJobs' and sc.[name] = 'FremdVerw')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [FremdVerw] 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_MareonJobs' and sc.[name] = 'GrossAuftr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [GrossAuftr] 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_MareonJobs' and sc.[name] = 'TypeValue')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ADD [TypeValue] char(20) 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_MareonJobs' and sc.[name] = 'UNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [UNR] char(20)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'JobERP')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [JobERP] char(30)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'CraftsPN')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [CraftsPN] char(10)
END
GO
IF 1 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'Status')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [Status] char(1)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'WI')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [WI] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'HS')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [HS] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'ME')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [ME] char(20)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'Type')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [Type] char(2)
END
GO
IF 200 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'Location')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [Location] char(200)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'EP')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [EP] char(20)
END
GO
IF 12 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'ZeitVon')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [ZeitVon] char(12)
END
GO
IF 12 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'ZeitBis')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [ZeitBis] char(12)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'SubUNR')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [SubUNR] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'MareonNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [MareonNo] char(20)
END
GO
IF 30 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'DisplayNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [DisplayNo] char(30)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'tradeKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [tradeKey] char(20)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'trade')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [trade] char(50)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'Description')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [Description] char(50)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'msOrderType')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [msOrderType] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'msIdentKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [msIdentKey] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'msIventKey')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [msIventKey] char(20)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'msDescr')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [msDescr] char(50)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'NrBsh')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [NrBsh] char(20)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'Barcode')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [Barcode] char(50)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'CancelRs')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [CancelRs] char(80)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'OfferNo')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [OfferNo] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_MareonJobs' and sc.[name] = 'TypeValue')
BEGIN
  ALTER TABLE [dbo].[ut_MareonJobs] ALTER COLUMN [TypeValue] char(20)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'MareonJobs')
  DROP VIEW [dbo].[MareonJobs]
GO
CREATE VIEW [dbo].[MareonJobs] AS
  SELECT * FROM [dbo].[ut_MareonJobs]
GO
CREATE TABLE [dbo].[ut_MareonJobs_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(80) NOT NULL
  ,[Key01_Value] CHAR(70) NOT NULL
  ,[Key02_Value] CHAR(70) NOT NULL
  ,[Key03_Value] CHAR(61) NOT NULL
  ,[Key04_Value] CHAR(71) NOT NULL
  ,[Key05_Value] CHAR(30) NOT NULL
  CONSTRAINT [Pk_ut_MareonJobs_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_MareonJobs_KeyDel] ON [dbo].[ut_MareonJobs]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_MareonJobs_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_MareonJobs_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value],[Key03_Value],[Key04_Value],[Key05_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(20),[UNR])+convert(char(30),[JobERP])+convert(char(20),[SubUNR])+STR(RecId,10))
     ,UPPER(convert(char(20),[UNR])+CONVERT(char(10),[Datum],120)+convert(char(30),[JobERP])+STR(RecId,10))
     ,UPPER(CONVERT(char(10),[Datum],120)+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR(RecId,10))
     ,UPPER(convert(char(1),[Status])+CONVERT(char(10),[Datum],120)+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR(RecId,10))
     ,UPPER(convert(char(20),[NrBsh])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_MareonJobs_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(20),[UNR])+convert(char(30),[JobERP])+convert(char(20),[SubUNR])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[UNR])+CONVERT(char(10),[Datum],120)+convert(char(30),[JobERP])+STR([RecId],10))
   ,[Key02_Value] = UPPER(CONVERT(char(10),[Datum],120)+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR([RecId],10))
   ,[Key03_Value] = UPPER(convert(char(1),[Status])+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(1),[Status])+CONVERT(char(10),[Datum],120)+convert(char(20),[UNR])+convert(char(30),[JobERP])+STR([RecId],10))
   ,[Key05_Value] = UPPER(convert(char(20),[NrBsh])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_MareonJobs')
  DROP PROCEDURE [dbo].[up_Add_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Add_MareonJobs] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_MareonJobs])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonJobs] (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_MareonJobs')
  DROP PROCEDURE [dbo].[up_Upd_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Upd_MareonJobs]
  @RI integer
 ,@Parm_UNR char(20)
 ,@Parm_JobERP char(30)
 ,@Parm_HostDate datetime
 ,@Parm_CraftsPN char(10)
 ,@Parm_Status char(1)
 ,@Parm_Datum datetime
 ,@Parm_WI char(20)
 ,@Parm_HS char(20)
 ,@Parm_ME char(20)
 ,@Parm_Type char(2)
 ,@Parm_JobPhoned tinyint
 ,@Parm_Location char(200)
 ,@Parm_EP char(20)
 ,@Parm_Costs float
 ,@Parm_TerminVon datetime
 ,@Parm_ZeitVon char(12)
 ,@Parm_TerminBis datetime
 ,@Parm_ZeitBis char(12)
 ,@Parm_TextId integer
 ,@Parm_InstrId integer
 ,@Parm_SubUNR char(20)
 ,@Parm_Warranty tinyint
 ,@Parm_TodoFromJob tinyint
 ,@Parm_MareonNo char(20)
 ,@Parm_Modify datetime
 ,@Parm_DisplayNo char(30)
 ,@Parm_Insurance tinyint
 ,@Parm_dateWithTe tinyint
 ,@Parm_tradeKey char(20)
 ,@Parm_trade char(50)
 ,@Parm_Description char(50)
 ,@Parm_measureSvc tinyint
 ,@Parm_msOrderType char(20)
 ,@Parm_msIdentKey char(20)
 ,@Parm_msIventKey char(20)
 ,@Parm_msDescr char(50)
 ,@Parm_NrBsh char(20)
 ,@Parm_Woche integer
 ,@Parm_Barcode char(50)
 ,@Parm_CancelRs char(80)
 ,@Parm_EStG35a integer
 ,@Parm_OfferDate datetime
 ,@Parm_OfferNo char(20)
 ,@Parm_OfferPrice float
 ,@Parm_FPA tinyint
 ,@Parm_FremdVerw tinyint
 ,@Parm_GrossAuftr tinyint
 ,@Parm_TypeValue char(20)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_MareonJobs] SET
     [UNR] = RTRIM(@Parm_UNR)
    ,[JobERP] = RTRIM(@Parm_JobERP)
    ,[HostDate] = @Parm_HostDate
    ,[CraftsPN] = RTRIM(@Parm_CraftsPN)
    ,[Status] = RTRIM(@Parm_Status)
    ,[Datum] = @Parm_Datum
    ,[WI] = RTRIM(@Parm_WI)
    ,[HS] = RTRIM(@Parm_HS)
    ,[ME] = RTRIM(@Parm_ME)
    ,[Type] = RTRIM(@Parm_Type)
    ,[JobPhoned] = @Parm_JobPhoned
    ,[Location] = RTRIM(@Parm_Location)
    ,[EP] = RTRIM(@Parm_EP)
    ,[Costs] = @Parm_Costs
    ,[TerminVon] = @Parm_TerminVon
    ,[ZeitVon] = RTRIM(@Parm_ZeitVon)
    ,[TerminBis] = @Parm_TerminBis
    ,[ZeitBis] = RTRIM(@Parm_ZeitBis)
    ,[TextId] = @Parm_TextId
    ,[InstrId] = @Parm_InstrId
    ,[SubUNR] = RTRIM(@Parm_SubUNR)
    ,[Warranty] = @Parm_Warranty
    ,[TodoFromJob] = @Parm_TodoFromJob
    ,[MareonNo] = RTRIM(@Parm_MareonNo)
    ,[Modify] = @Parm_Modify
    ,[DisplayNo] = RTRIM(@Parm_DisplayNo)
    ,[Insurance] = @Parm_Insurance
    ,[dateWithTe] = @Parm_dateWithTe
    ,[tradeKey] = RTRIM(@Parm_tradeKey)
    ,[trade] = RTRIM(@Parm_trade)
    ,[Description] = RTRIM(@Parm_Description)
    ,[measureSvc] = @Parm_measureSvc
    ,[msOrderType] = RTRIM(@Parm_msOrderType)
    ,[msIdentKey] = RTRIM(@Parm_msIdentKey)
    ,[msIventKey] = RTRIM(@Parm_msIventKey)
    ,[msDescr] = RTRIM(@Parm_msDescr)
    ,[NrBsh] = RTRIM(@Parm_NrBsh)
    ,[Woche] = @Parm_Woche
    ,[Barcode] = RTRIM(@Parm_Barcode)
    ,[CancelRs] = RTRIM(@Parm_CancelRs)
    ,[EStG35a] = @Parm_EStG35a
    ,[OfferDate] = @Parm_OfferDate
    ,[OfferNo] = RTRIM(@Parm_OfferNo)
    ,[OfferPrice] = @Parm_OfferPrice
    ,[FPA] = @Parm_FPA
    ,[FremdVerw] = @Parm_FremdVerw
    ,[GrossAuftr] = @Parm_GrossAuftr
    ,[TypeValue] = RTRIM(@Parm_TypeValue)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_MareonJobs')
  DROP PROCEDURE [dbo].[up_Sel_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Sel_MareonJobs]
  @RI integer
AS
SELECT
     [UNR]
    ,[JobERP]
    ,[HostDate]
    ,[CraftsPN]
    ,[Status]
    ,[Datum]
    ,[WI]
    ,[HS]
    ,[ME]
    ,[Type]
    ,[JobPhoned]
    ,[Location]
    ,[EP]
    ,[Costs]
    ,[TerminVon]
    ,[ZeitVon]
    ,[TerminBis]
    ,[ZeitBis]
    ,[TextId]
    ,[InstrId]
    ,[SubUNR]
    ,[Warranty]
    ,[TodoFromJob]
    ,[MareonNo]
    ,[Modify]
    ,[DisplayNo]
    ,[Insurance]
    ,[dateWithTe]
    ,[tradeKey]
    ,[trade]
    ,[Description]
    ,[measureSvc]
    ,[msOrderType]
    ,[msIdentKey]
    ,[msIventKey]
    ,[msDescr]
    ,[NrBsh]
    ,[Woche]
    ,[Barcode]
    ,[CancelRs]
    ,[EStG35a]
    ,[OfferDate]
    ,[OfferNo]
    ,[OfferPrice]
    ,[FPA]
    ,[FremdVerw]
    ,[GrossAuftr]
    ,[TypeValue]
  FROM [dbo].[ut_MareonJobs]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_MareonJobs')
  DROP PROCEDURE [dbo].[up_Del_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Del_MareonJobs]
  @RI integer
AS
  DELETE FROM [dbo].[ut_MareonJobs] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_MareonJobs')
  DROP PROCEDURE [dbo].[up_Reorg_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Reorg_MareonJobs]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_MareonJobs] 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_MareonJobs] 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_MareonJobs] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_MareonJobs')
  DROP PROCEDURE [dbo].[up_Append_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_Append_MareonJobs]
  @Parm_UNR char(20)
 ,@Parm_JobERP char(30)
 ,@Parm_HostDate datetime
 ,@Parm_CraftsPN char(10)
 ,@Parm_Status char(1)
 ,@Parm_Datum datetime
 ,@Parm_WI char(20)
 ,@Parm_HS char(20)
 ,@Parm_ME char(20)
 ,@Parm_Type char(2)
 ,@Parm_JobPhoned tinyint
 ,@Parm_Location char(200)
 ,@Parm_EP char(20)
 ,@Parm_Costs float
 ,@Parm_TerminVon datetime
 ,@Parm_ZeitVon char(12)
 ,@Parm_TerminBis datetime
 ,@Parm_ZeitBis char(12)
 ,@Parm_TextId integer
 ,@Parm_InstrId integer
 ,@Parm_SubUNR char(20)
 ,@Parm_Warranty tinyint
 ,@Parm_TodoFromJob tinyint
 ,@Parm_MareonNo char(20)
 ,@Parm_Modify datetime
 ,@Parm_DisplayNo char(30)
 ,@Parm_Insurance tinyint
 ,@Parm_dateWithTe tinyint
 ,@Parm_tradeKey char(20)
 ,@Parm_trade char(50)
 ,@Parm_Description char(50)
 ,@Parm_measureSvc tinyint
 ,@Parm_msOrderType char(20)
 ,@Parm_msIdentKey char(20)
 ,@Parm_msIventKey char(20)
 ,@Parm_msDescr char(50)
 ,@Parm_NrBsh char(20)
 ,@Parm_Woche integer
 ,@Parm_Barcode char(50)
 ,@Parm_CancelRs char(80)
 ,@Parm_EStG35a integer
 ,@Parm_OfferDate datetime
 ,@Parm_OfferNo char(20)
 ,@Parm_OfferPrice float
 ,@Parm_FPA tinyint
 ,@Parm_FremdVerw tinyint
 ,@Parm_GrossAuftr tinyint
 ,@Parm_TypeValue char(20)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_MareonJobs])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_MareonJobs] (
    RecId
   ,[UNR]
   ,[JobERP]
   ,[HostDate]
   ,[CraftsPN]
   ,[Status]
   ,[Datum]
   ,[WI]
   ,[HS]
   ,[ME]
   ,[Type]
   ,[JobPhoned]
   ,[Location]
   ,[EP]
   ,[Costs]
   ,[TerminVon]
   ,[ZeitVon]
   ,[TerminBis]
   ,[ZeitBis]
   ,[TextId]
   ,[InstrId]
   ,[SubUNR]
   ,[Warranty]
   ,[TodoFromJob]
   ,[MareonNo]
   ,[Modify]
   ,[DisplayNo]
   ,[Insurance]
   ,[dateWithTe]
   ,[tradeKey]
   ,[trade]
   ,[Description]
   ,[measureSvc]
   ,[msOrderType]
   ,[msIdentKey]
   ,[msIventKey]
   ,[msDescr]
   ,[NrBsh]
   ,[Woche]
   ,[Barcode]
   ,[CancelRs]
   ,[EStG35a]
   ,[OfferDate]
   ,[OfferNo]
   ,[OfferPrice]
   ,[FPA]
   ,[FremdVerw]
   ,[GrossAuftr]
   ,[TypeValue]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_UNR)
   ,RTRIM(@Parm_JobERP)
   ,@Parm_HostDate
   ,RTRIM(@Parm_CraftsPN)
   ,RTRIM(@Parm_Status)
   ,@Parm_Datum
   ,RTRIM(@Parm_WI)
   ,RTRIM(@Parm_HS)
   ,RTRIM(@Parm_ME)
   ,RTRIM(@Parm_Type)
   ,@Parm_JobPhoned
   ,RTRIM(@Parm_Location)
   ,RTRIM(@Parm_EP)
   ,@Parm_Costs
   ,@Parm_TerminVon
   ,RTRIM(@Parm_ZeitVon)
   ,@Parm_TerminBis
   ,RTRIM(@Parm_ZeitBis)
   ,@Parm_TextId
   ,@Parm_InstrId
   ,RTRIM(@Parm_SubUNR)
   ,@Parm_Warranty
   ,@Parm_TodoFromJob
   ,RTRIM(@Parm_MareonNo)
   ,@Parm_Modify
   ,RTRIM(@Parm_DisplayNo)
   ,@Parm_Insurance
   ,@Parm_dateWithTe
   ,RTRIM(@Parm_tradeKey)
   ,RTRIM(@Parm_trade)
   ,RTRIM(@Parm_Description)
   ,@Parm_measureSvc
   ,RTRIM(@Parm_msOrderType)
   ,RTRIM(@Parm_msIdentKey)
   ,RTRIM(@Parm_msIventKey)
   ,RTRIM(@Parm_msDescr)
   ,RTRIM(@Parm_NrBsh)
   ,@Parm_Woche
   ,RTRIM(@Parm_Barcode)
   ,RTRIM(@Parm_CancelRs)
   ,@Parm_EStG35a
   ,@Parm_OfferDate
   ,RTRIM(@Parm_OfferNo)
   ,@Parm_OfferPrice
   ,@Parm_FPA
   ,@Parm_FremdVerw
   ,@Parm_GrossAuftr
   ,RTRIM(@Parm_TypeValue)
       )
  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_MareonJobs')
  DROP PROCEDURE [dbo].[up_TrSel_MareonJobs]
GO
CREATE PROCEDURE [dbo].[up_TrSel_MareonJobs]
AS
  SELECT   RecId,
      LTRIM(RTRIM([UNR]))
      +LTRIM(RTRIM([JobERP]))
      +LTRIM(RTRIM([CraftsPN]))
      +LTRIM(RTRIM([Status]))
      +LTRIM(RTRIM([WI]))
      +LTRIM(RTRIM([HS]))
      +LTRIM(RTRIM([ME]))
      +LTRIM(RTRIM([Type]))
      +LTRIM(RTRIM([Location]))
      +LTRIM(RTRIM([EP]))
      +LTRIM(RTRIM([ZeitVon]))
      +LTRIM(RTRIM([ZeitBis]))
      +LTRIM(RTRIM([SubUNR]))
      +LTRIM(RTRIM([MareonNo]))
      +LTRIM(RTRIM([DisplayNo]))
      +LTRIM(RTRIM([tradeKey]))
      +LTRIM(RTRIM([trade]))
      +LTRIM(RTRIM([Description]))
      +LTRIM(RTRIM([msOrderType]))
      +LTRIM(RTRIM([msIdentKey]))
      +LTRIM(RTRIM([msIventKey]))
      +LTRIM(RTRIM([msDescr]))
      +LTRIM(RTRIM([NrBsh]))
      +LTRIM(RTRIM([Barcode]))
      +LTRIM(RTRIM([CancelRs]))
      +LTRIM(RTRIM([OfferNo]))
      +LTRIM(RTRIM([TypeValue]))
    AS Data
  FROM     [dbo].[ut_MareonJobs]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_MareonJobs_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key00')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_MareonJobs_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key01')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_MareonJobs_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key02')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key02]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key03] ON [dbo].[ut_MareonJobs_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key03')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key03]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_MareonJobs_Keys]
( [Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key04')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key04]
GO

CREATE PROCEDURE [dbo].[up_First_MareonJobs_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys] ORDER BY [Key04_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_MareonJobs_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys] ORDER BY [Key04_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_MareonJobs_Key04] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys]
  WHERE [Key04_Value] > (SELECT [Key04_Value] FROM [dbo].[ut_MareonJobs_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_MareonJobs_Key04] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys]
  WHERE [Key04_Value] > (SELECT [Key04_Value] FROM [dbo].[ut_MareonJobs_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value]
GO

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

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

CREATE INDEX [Ik_Key05] ON [dbo].[ut_MareonJobs_Keys]
( [Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_First_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_Last_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_Prior_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_Next_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_Next50_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_FindL_MareonJobs_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_MareonJobs_Key05')
  DROP PROCEDURE [dbo].[up_FindF_MareonJobs_Key05]
GO

CREATE PROCEDURE [dbo].[up_First_MareonJobs_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys] ORDER BY [Key05_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_MareonJobs_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys] ORDER BY [Key05_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_MareonJobs_Key05] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys]
  WHERE [Key05_Value] > (SELECT [Key05_Value] FROM [dbo].[ut_MareonJobs_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_MareonJobs_Key05] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys]
  WHERE [Key05_Value] > (SELECT [Key05_Value] FROM [dbo].[ut_MareonJobs_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value]
GO

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

CREATE PROCEDURE [dbo].[up_FindF_MareonJobs_Key05] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key05_Value] AS Key_Value FROM [dbo].[ut_MareonJobs_Keys]
      WHERE [Key05_Value] >= SUBSTRING(@xKey,1,@xLen)
      ORDER BY [Key05_Value]
    ) a
  WHERE a.Key_Value like SUBSTRING(@xKey,1,@xLen)+'%'
GO

CREATE PROCEDURE [dbo].[up_FindL_MareonJobs_Key05] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_MareonJobs_Keys]
  WHERE [Key05_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key05_Value] DESC
GO

