------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelFormHeader')
BEGIN
CREATE TABLE [dbo].[ut_BelFormHeader]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[FormNr] integer DEFAULT 0
  ,[FormName] char(50) DEFAULT ' '
  ,[DefForm] integer DEFAULT 0
  ,[PageLen] integer DEFAULT 0
  ,[Page1Offset] integer DEFAULT 0
  ,[Page1Max] integer DEFAULT 0
  ,[Page2Offset] integer DEFAULT 0
  ,[Page2Max] integer DEFAULT 0
  ,[LineSpace] float DEFAULT 0
  ,[HeadLines] integer DEFAULT 0
  ,[FontNameA] char(40) DEFAULT ' '
  ,[FontNameB] char(40) DEFAULT ' '
  ,[FontNameC] char(40) DEFAULT ' '
  ,[FontNameD] char(40) DEFAULT ' '
  ,[FontNameE] char(40) DEFAULT ' '
  ,[FontNameF] char(40) DEFAULT ' '
  ,[FontNameG] char(40) DEFAULT ' '
  ,[FontNameH] char(40) DEFAULT ' '
  ,[FontNameI] char(40) DEFAULT ' '
  ,[FontNameJ] char(40) DEFAULT ' '
  ,[FontNameK] char(40) DEFAULT ' '
  ,[FontNameL] char(40) DEFAULT ' '
  ,[MacroC] char(80) DEFAULT ' '
  ,[MacroE] char(80) DEFAULT ' '
  ,[MacroG] char(80) DEFAULT ' '
  ,[MacroM] char(80) DEFAULT ' '
  ,[MacroN] char(80) DEFAULT ' '
  ,[MacroL] char(80) DEFAULT ' '
  ,[MacroP] char(80) DEFAULT ' '
  ,[MacroR] char(80) DEFAULT ' '
  ,[MacroT] char(80) DEFAULT ' '
  ,[MacroW] char(80) DEFAULT ' '
  ,[MacroX] char(80) DEFAULT ' '
  ,[MacroZ] char(80) DEFAULT ' '
  ,[bAutoHead] tinyint DEFAULT 0
  ,[TitelSumme] integer DEFAULT 0
  ,[NettoSumme] integer DEFAULT 0
  ,[MWST] integer DEFAULT 0
  ,[MWST13B] integer DEFAULT 0
  ,[DevOffsX] float DEFAULT 0
  ,[DevOffsY] float DEFAULT 0
  ,[DevMaps] char(20) DEFAULT ' '
  ,[PrjNr] char(8) DEFAULT ' '
  ,[BelArt] char(2) DEFAULT ' '
  ,[BelNr] char(8) DEFAULT ' '
  ,[AddrMode] integer DEFAULT 0
  ,[PosMode] integer DEFAULT 0
  CONSTRAINT [Pk_BelFormHeader]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormHeader_KeyDel')
  DROP TRIGGER [dbo].[tr_BelFormHeader_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelFormHeader_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelFormHeader_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelFormHeader_Keys')
  DROP TABLE [dbo].[ut_BelFormHeader_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FormNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FormNr] 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_BelFormHeader' and sc.[name] = 'FormName')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FormName] 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_BelFormHeader' and sc.[name] = 'DefForm')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [DefForm] 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_BelFormHeader' and sc.[name] = 'PageLen')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [PageLen] 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_BelFormHeader' and sc.[name] = 'Page1Offset')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [Page1Offset] 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_BelFormHeader' and sc.[name] = 'Page1Max')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [Page1Max] 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_BelFormHeader' and sc.[name] = 'Page2Offset')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [Page2Offset] 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_BelFormHeader' and sc.[name] = 'Page2Max')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [Page2Max] 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_BelFormHeader' and sc.[name] = 'LineSpace')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [LineSpace] 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_BelFormHeader' and sc.[name] = 'HeadLines')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [HeadLines] 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_BelFormHeader' and sc.[name] = 'FontNameA')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameA] 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_BelFormHeader' and sc.[name] = 'FontNameB')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameB] 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_BelFormHeader' and sc.[name] = 'FontNameC')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameC] 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_BelFormHeader' and sc.[name] = 'FontNameD')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameD] 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_BelFormHeader' and sc.[name] = 'FontNameE')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameE] 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_BelFormHeader' and sc.[name] = 'FontNameF')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameF] 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_BelFormHeader' and sc.[name] = 'FontNameG')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameG] 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_BelFormHeader' and sc.[name] = 'FontNameH')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameH] 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_BelFormHeader' and sc.[name] = 'FontNameI')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameI] 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_BelFormHeader' and sc.[name] = 'FontNameJ')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameJ] 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_BelFormHeader' and sc.[name] = 'FontNameK')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameK] 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_BelFormHeader' and sc.[name] = 'FontNameL')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [FontNameL] 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_BelFormHeader' and sc.[name] = 'MacroC')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroC] 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_BelFormHeader' and sc.[name] = 'MacroE')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroE] 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_BelFormHeader' and sc.[name] = 'MacroG')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroG] 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_BelFormHeader' and sc.[name] = 'MacroM')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroM] 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_BelFormHeader' and sc.[name] = 'MacroN')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroN] 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_BelFormHeader' and sc.[name] = 'MacroL')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroL] 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_BelFormHeader' and sc.[name] = 'MacroP')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroP] 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_BelFormHeader' and sc.[name] = 'MacroR')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroR] 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_BelFormHeader' and sc.[name] = 'MacroT')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroT] 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_BelFormHeader' and sc.[name] = 'MacroW')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroW] 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_BelFormHeader' and sc.[name] = 'MacroX')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroX] 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_BelFormHeader' and sc.[name] = 'MacroZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MacroZ] 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_BelFormHeader' and sc.[name] = 'bAutoHead')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [bAutoHead] 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_BelFormHeader' and sc.[name] = 'TitelSumme')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [TitelSumme] 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_BelFormHeader' and sc.[name] = 'NettoSumme')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [NettoSumme] 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_BelFormHeader' and sc.[name] = 'MWST')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MWST] 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_BelFormHeader' and sc.[name] = 'MWST13B')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [MWST13B] 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_BelFormHeader' and sc.[name] = 'DevOffsX')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [DevOffsX] 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_BelFormHeader' and sc.[name] = 'DevOffsY')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [DevOffsY] 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_BelFormHeader' and sc.[name] = 'DevMaps')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [DevMaps] 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_BelFormHeader' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [PrjNr] 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_BelFormHeader' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [BelArt] 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_BelFormHeader' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [BelNr] 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_BelFormHeader' and sc.[name] = 'AddrMode')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [AddrMode] 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_BelFormHeader' and sc.[name] = 'PosMode')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ADD [PosMode] integer NOT NULL DEFAULT 0
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FormName')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FormName] char(50)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameA')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameA] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameB')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameB] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameC')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameC] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameD')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameD] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameE')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameE] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameF')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameF] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameG')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameG] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameH')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameH] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameI')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameI] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameJ')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameJ] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameK')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameK] char(40)
END
GO
IF 40 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'FontNameL')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [FontNameL] char(40)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroC')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroC] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroE')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroE] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroG')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroG] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroM')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroM] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroN')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroN] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroL')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroL] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroP')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroP] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroR')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroR] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroT')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroT] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroW')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroW] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroX')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroX] char(80)
END
GO
IF 80 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'MacroZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [MacroZ] char(80)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'DevMaps')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [DevMaps] char(20)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [PrjNr] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [BelArt] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelFormHeader' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelFormHeader] ALTER COLUMN [BelNr] char(8)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelFormHeader')
  DROP VIEW [dbo].[BelFormHeader]
GO
CREATE VIEW [dbo].[BelFormHeader] AS
  SELECT * FROM [dbo].[ut_BelFormHeader]
GO
CREATE TABLE [dbo].[ut_BelFormHeader_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(18) NOT NULL
  ,[Key01_Value] CHAR(19) NOT NULL
  ,[Key02_Value] CHAR(28) NOT NULL
  CONSTRAINT [Pk_ut_BelFormHeader_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_BelFormHeader_KeyDel] ON [dbo].[ut_BelFormHeader]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_BelFormHeader_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_BelFormHeader_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value],[Key02_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([FormNr],8,0)+STR(RecId,10))
     ,UPPER(STR([DefForm],1,0)+STR([FormNr],8,0)+STR(RecId,10))
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_BelFormHeader_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([FormNr],8,0)+STR([RecId],10))
   ,[Key01_Value] = UPPER(STR([DefForm],1,0)+STR([FormNr],8,0)+STR([RecId],10))
   ,[Key02_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Add_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Add_BelFormHeader] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_BelFormHeader])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormHeader] (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_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Upd_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelFormHeader]
  @RI integer
 ,@Parm_FormNr integer
 ,@Parm_FormName char(50)
 ,@Parm_DefForm integer
 ,@Parm_PageLen integer
 ,@Parm_Page1Offset integer
 ,@Parm_Page1Max integer
 ,@Parm_Page2Offset integer
 ,@Parm_Page2Max integer
 ,@Parm_LineSpace float
 ,@Parm_HeadLines integer
 ,@Parm_FontNameA char(40)
 ,@Parm_FontNameB char(40)
 ,@Parm_FontNameC char(40)
 ,@Parm_FontNameD char(40)
 ,@Parm_FontNameE char(40)
 ,@Parm_FontNameF char(40)
 ,@Parm_FontNameG char(40)
 ,@Parm_FontNameH char(40)
 ,@Parm_FontNameI char(40)
 ,@Parm_FontNameJ char(40)
 ,@Parm_FontNameK char(40)
 ,@Parm_FontNameL char(40)
 ,@Parm_MacroC char(80)
 ,@Parm_MacroE char(80)
 ,@Parm_MacroG char(80)
 ,@Parm_MacroM char(80)
 ,@Parm_MacroN char(80)
 ,@Parm_MacroL char(80)
 ,@Parm_MacroP char(80)
 ,@Parm_MacroR char(80)
 ,@Parm_MacroT char(80)
 ,@Parm_MacroW char(80)
 ,@Parm_MacroX char(80)
 ,@Parm_MacroZ char(80)
 ,@Parm_bAutoHead tinyint
 ,@Parm_TitelSumme integer
 ,@Parm_NettoSumme integer
 ,@Parm_MWST integer
 ,@Parm_MWST13B integer
 ,@Parm_DevOffsX float
 ,@Parm_DevOffsY float
 ,@Parm_DevMaps char(20)
 ,@Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_AddrMode integer
 ,@Parm_PosMode integer
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_BelFormHeader] SET
     [FormNr] = @Parm_FormNr
    ,[FormName] = RTRIM(@Parm_FormName)
    ,[DefForm] = @Parm_DefForm
    ,[PageLen] = @Parm_PageLen
    ,[Page1Offset] = @Parm_Page1Offset
    ,[Page1Max] = @Parm_Page1Max
    ,[Page2Offset] = @Parm_Page2Offset
    ,[Page2Max] = @Parm_Page2Max
    ,[LineSpace] = @Parm_LineSpace
    ,[HeadLines] = @Parm_HeadLines
    ,[FontNameA] = RTRIM(@Parm_FontNameA)
    ,[FontNameB] = RTRIM(@Parm_FontNameB)
    ,[FontNameC] = RTRIM(@Parm_FontNameC)
    ,[FontNameD] = RTRIM(@Parm_FontNameD)
    ,[FontNameE] = RTRIM(@Parm_FontNameE)
    ,[FontNameF] = RTRIM(@Parm_FontNameF)
    ,[FontNameG] = RTRIM(@Parm_FontNameG)
    ,[FontNameH] = RTRIM(@Parm_FontNameH)
    ,[FontNameI] = RTRIM(@Parm_FontNameI)
    ,[FontNameJ] = RTRIM(@Parm_FontNameJ)
    ,[FontNameK] = RTRIM(@Parm_FontNameK)
    ,[FontNameL] = RTRIM(@Parm_FontNameL)
    ,[MacroC] = RTRIM(@Parm_MacroC)
    ,[MacroE] = RTRIM(@Parm_MacroE)
    ,[MacroG] = RTRIM(@Parm_MacroG)
    ,[MacroM] = RTRIM(@Parm_MacroM)
    ,[MacroN] = RTRIM(@Parm_MacroN)
    ,[MacroL] = RTRIM(@Parm_MacroL)
    ,[MacroP] = RTRIM(@Parm_MacroP)
    ,[MacroR] = RTRIM(@Parm_MacroR)
    ,[MacroT] = RTRIM(@Parm_MacroT)
    ,[MacroW] = RTRIM(@Parm_MacroW)
    ,[MacroX] = RTRIM(@Parm_MacroX)
    ,[MacroZ] = RTRIM(@Parm_MacroZ)
    ,[bAutoHead] = @Parm_bAutoHead
    ,[TitelSumme] = @Parm_TitelSumme
    ,[NettoSumme] = @Parm_NettoSumme
    ,[MWST] = @Parm_MWST
    ,[MWST13B] = @Parm_MWST13B
    ,[DevOffsX] = @Parm_DevOffsX
    ,[DevOffsY] = @Parm_DevOffsY
    ,[DevMaps] = RTRIM(@Parm_DevMaps)
    ,[PrjNr] = RTRIM(@Parm_PrjNr)
    ,[BelArt] = RTRIM(@Parm_BelArt)
    ,[BelNr] = RTRIM(@Parm_BelNr)
    ,[AddrMode] = @Parm_AddrMode
    ,[PosMode] = @Parm_PosMode
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Sel_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelFormHeader]
  @RI integer
AS
SELECT
     [FormNr]
    ,[FormName]
    ,[DefForm]
    ,[PageLen]
    ,[Page1Offset]
    ,[Page1Max]
    ,[Page2Offset]
    ,[Page2Max]
    ,[LineSpace]
    ,[HeadLines]
    ,[FontNameA]
    ,[FontNameB]
    ,[FontNameC]
    ,[FontNameD]
    ,[FontNameE]
    ,[FontNameF]
    ,[FontNameG]
    ,[FontNameH]
    ,[FontNameI]
    ,[FontNameJ]
    ,[FontNameK]
    ,[FontNameL]
    ,[MacroC]
    ,[MacroE]
    ,[MacroG]
    ,[MacroM]
    ,[MacroN]
    ,[MacroL]
    ,[MacroP]
    ,[MacroR]
    ,[MacroT]
    ,[MacroW]
    ,[MacroX]
    ,[MacroZ]
    ,[bAutoHead]
    ,[TitelSumme]
    ,[NettoSumme]
    ,[MWST]
    ,[MWST13B]
    ,[DevOffsX]
    ,[DevOffsY]
    ,[DevMaps]
    ,[PrjNr]
    ,[BelArt]
    ,[BelNr]
    ,[AddrMode]
    ,[PosMode]
  FROM [dbo].[ut_BelFormHeader]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Del_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Del_BelFormHeader]
  @RI integer
AS
  DELETE FROM [dbo].[ut_BelFormHeader] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Reorg_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelFormHeader]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelFormHeader] 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_BelFormHeader] 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_BelFormHeader] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelFormHeader')
  DROP PROCEDURE [dbo].[up_Append_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_Append_BelFormHeader]
  @Parm_FormNr integer
 ,@Parm_FormName char(50)
 ,@Parm_DefForm integer
 ,@Parm_PageLen integer
 ,@Parm_Page1Offset integer
 ,@Parm_Page1Max integer
 ,@Parm_Page2Offset integer
 ,@Parm_Page2Max integer
 ,@Parm_LineSpace float
 ,@Parm_HeadLines integer
 ,@Parm_FontNameA char(40)
 ,@Parm_FontNameB char(40)
 ,@Parm_FontNameC char(40)
 ,@Parm_FontNameD char(40)
 ,@Parm_FontNameE char(40)
 ,@Parm_FontNameF char(40)
 ,@Parm_FontNameG char(40)
 ,@Parm_FontNameH char(40)
 ,@Parm_FontNameI char(40)
 ,@Parm_FontNameJ char(40)
 ,@Parm_FontNameK char(40)
 ,@Parm_FontNameL char(40)
 ,@Parm_MacroC char(80)
 ,@Parm_MacroE char(80)
 ,@Parm_MacroG char(80)
 ,@Parm_MacroM char(80)
 ,@Parm_MacroN char(80)
 ,@Parm_MacroL char(80)
 ,@Parm_MacroP char(80)
 ,@Parm_MacroR char(80)
 ,@Parm_MacroT char(80)
 ,@Parm_MacroW char(80)
 ,@Parm_MacroX char(80)
 ,@Parm_MacroZ char(80)
 ,@Parm_bAutoHead tinyint
 ,@Parm_TitelSumme integer
 ,@Parm_NettoSumme integer
 ,@Parm_MWST integer
 ,@Parm_MWST13B integer
 ,@Parm_DevOffsX float
 ,@Parm_DevOffsY float
 ,@Parm_DevMaps char(20)
 ,@Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_AddrMode integer
 ,@Parm_PosMode integer
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_BelFormHeader])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelFormHeader] (
    RecId
   ,[FormNr]
   ,[FormName]
   ,[DefForm]
   ,[PageLen]
   ,[Page1Offset]
   ,[Page1Max]
   ,[Page2Offset]
   ,[Page2Max]
   ,[LineSpace]
   ,[HeadLines]
   ,[FontNameA]
   ,[FontNameB]
   ,[FontNameC]
   ,[FontNameD]
   ,[FontNameE]
   ,[FontNameF]
   ,[FontNameG]
   ,[FontNameH]
   ,[FontNameI]
   ,[FontNameJ]
   ,[FontNameK]
   ,[FontNameL]
   ,[MacroC]
   ,[MacroE]
   ,[MacroG]
   ,[MacroM]
   ,[MacroN]
   ,[MacroL]
   ,[MacroP]
   ,[MacroR]
   ,[MacroT]
   ,[MacroW]
   ,[MacroX]
   ,[MacroZ]
   ,[bAutoHead]
   ,[TitelSumme]
   ,[NettoSumme]
   ,[MWST]
   ,[MWST13B]
   ,[DevOffsX]
   ,[DevOffsY]
   ,[DevMaps]
   ,[PrjNr]
   ,[BelArt]
   ,[BelNr]
   ,[AddrMode]
   ,[PosMode]
     ) VALUES (
    @NeueId
   ,@Parm_FormNr
   ,RTRIM(@Parm_FormName)
   ,@Parm_DefForm
   ,@Parm_PageLen
   ,@Parm_Page1Offset
   ,@Parm_Page1Max
   ,@Parm_Page2Offset
   ,@Parm_Page2Max
   ,@Parm_LineSpace
   ,@Parm_HeadLines
   ,RTRIM(@Parm_FontNameA)
   ,RTRIM(@Parm_FontNameB)
   ,RTRIM(@Parm_FontNameC)
   ,RTRIM(@Parm_FontNameD)
   ,RTRIM(@Parm_FontNameE)
   ,RTRIM(@Parm_FontNameF)
   ,RTRIM(@Parm_FontNameG)
   ,RTRIM(@Parm_FontNameH)
   ,RTRIM(@Parm_FontNameI)
   ,RTRIM(@Parm_FontNameJ)
   ,RTRIM(@Parm_FontNameK)
   ,RTRIM(@Parm_FontNameL)
   ,RTRIM(@Parm_MacroC)
   ,RTRIM(@Parm_MacroE)
   ,RTRIM(@Parm_MacroG)
   ,RTRIM(@Parm_MacroM)
   ,RTRIM(@Parm_MacroN)
   ,RTRIM(@Parm_MacroL)
   ,RTRIM(@Parm_MacroP)
   ,RTRIM(@Parm_MacroR)
   ,RTRIM(@Parm_MacroT)
   ,RTRIM(@Parm_MacroW)
   ,RTRIM(@Parm_MacroX)
   ,RTRIM(@Parm_MacroZ)
   ,@Parm_bAutoHead
   ,@Parm_TitelSumme
   ,@Parm_NettoSumme
   ,@Parm_MWST
   ,@Parm_MWST13B
   ,@Parm_DevOffsX
   ,@Parm_DevOffsY
   ,RTRIM(@Parm_DevMaps)
   ,RTRIM(@Parm_PrjNr)
   ,RTRIM(@Parm_BelArt)
   ,RTRIM(@Parm_BelNr)
   ,@Parm_AddrMode
   ,@Parm_PosMode
       )
  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_BelFormHeader')
  DROP PROCEDURE [dbo].[up_TrSel_BelFormHeader]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelFormHeader]
AS
  SELECT   RecId,
      LTRIM(RTRIM([FormName]))
      +LTRIM(RTRIM([FontNameA]))
      +LTRIM(RTRIM([FontNameB]))
      +LTRIM(RTRIM([FontNameC]))
      +LTRIM(RTRIM([FontNameD]))
      +LTRIM(RTRIM([FontNameE]))
      +LTRIM(RTRIM([FontNameF]))
      +LTRIM(RTRIM([FontNameG]))
      +LTRIM(RTRIM([FontNameH]))
      +LTRIM(RTRIM([FontNameI]))
      +LTRIM(RTRIM([FontNameJ]))
      +LTRIM(RTRIM([FontNameK]))
      +LTRIM(RTRIM([FontNameL]))
      +LTRIM(RTRIM([MacroC]))
      +LTRIM(RTRIM([MacroE]))
      +LTRIM(RTRIM([MacroG]))
      +LTRIM(RTRIM([MacroM]))
      +LTRIM(RTRIM([MacroN]))
      +LTRIM(RTRIM([MacroL]))
      +LTRIM(RTRIM([MacroP]))
      +LTRIM(RTRIM([MacroR]))
      +LTRIM(RTRIM([MacroT]))
      +LTRIM(RTRIM([MacroW]))
      +LTRIM(RTRIM([MacroX]))
      +LTRIM(RTRIM([MacroZ]))
      +LTRIM(RTRIM([DevMaps]))
      +LTRIM(RTRIM([PrjNr]))
      +LTRIM(RTRIM([BelArt]))
      +LTRIM(RTRIM([BelNr]))
    AS Data
  FROM     [dbo].[ut_BelFormHeader]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_BelFormHeader_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_First_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_Last_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_Prior_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_Next_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_Next50_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_FindL_BelFormHeader_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormHeader_Key00')
  DROP PROCEDURE [dbo].[up_FindF_BelFormHeader_Key00]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_BelFormHeader_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_First_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_Last_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_Prior_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_Next_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_Next50_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_FindL_BelFormHeader_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormHeader_Key01')
  DROP PROCEDURE [dbo].[up_FindF_BelFormHeader_Key01]
GO

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key02] ON [dbo].[ut_BelFormHeader_Keys]
( [Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_First_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_Last_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_Prior_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_Next_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_Next50_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_FindL_BelFormHeader_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelFormHeader_Key02')
  DROP PROCEDURE [dbo].[up_FindF_BelFormHeader_Key02]
GO

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

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

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

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

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

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

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

