-- This file is part of the it-crafts software and is subject to copyright protection.
-- (C) 2022..2026, All rights reserved by Steffen Anders, Elsteraue - Germany
-- Visit also https://www.it-crafts.de.
--

IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelKopfExt')
BEGIN
CREATE TABLE [dbo].[ut_BelKopfExt]
(
  [RecId]  integer NOT NULL
 ,[PrjNr] char(8) DEFAULT ''
 ,[BelArt] char(2) DEFAULT ''
 ,[BelNr] char(8) DEFAULT ''
 ,[NkMengen] integer DEFAULT 0
 ,[Lose] tinyint DEFAULT 0
 ,[GaebOz] char(9) DEFAULT ''
 ,[GaebDvNr] varchar(8) DEFAULT ''
 ,[GaebBietNr] varchar(3) DEFAULT ''
 ,[GaebVergNr] varchar(15) DEFAULT ''
 ,[Untertitel] integer DEFAULT 0
 ,[ZuschFrist] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[SubZeit] char(5) DEFAULT ''
 ,[GaebLVBez] varchar(40) DEFAULT ''
 ,[RwegSkonto] integer DEFAULT 0
 ,[LagerVerbu] tinyint DEFAULT 0
 ,[NewRwSusp] tinyint DEFAULT 0
 ,[CxLstgPos] integer DEFAULT 0
 ,[CxTextPos] integer DEFAULT 0
 ,[CxVtNtPos] integer DEFAULT 0
 ,[CxAufmass] integer DEFAULT 0
 ,[bFormKeys] tinyint DEFAULT 0
 ,[FormKeyFi] char(30) DEFAULT ''
 ,[Floskeln] integer DEFAULT 0
 ,[GAEBArtMo] tinyint DEFAULT 0
 ,[NrHwGC] char(15) DEFAULT ''
 ,[SuSpOpts] char(140) DEFAULT ''
 ,[CuPreis] float DEFAULT 0
 ,[CalcEk2Vk] tinyint DEFAULT 0
 ,[CalcAuf2Vk] tinyint DEFAULT 0
 ,[CalcNEP] tinyint DEFAULT 0
 ,[ProgVers] integer DEFAULT 0
 ,[Sum_Netto] float DEFAULT 0
 ,[Sum_Gesamt] float DEFAULT 0
 ,[Sum_Mwst] float DEFAULT 0
 ,[Sum_NettoB] float DEFAULT 0
 ,[ZUAB_BRUTTO] float DEFAULT 0
 ,[LVNETTO] float DEFAULT 0
 ,[LVMWST] float DEFAULT 0
 ,[LVBRUTTO] float DEFAULT 0
 ,[TRNet] float DEFAULT 0
 ,[TRMws] float DEFAULT 0
 ,[TRBru] float DEFAULT 0
 ,[TRNet_BEZ] float DEFAULT 0
 ,[TRMws_BEZ] float DEFAULT 0
 ,[TRBru_BEZ] float DEFAULT 0
 ,[SkontoBasis] float DEFAULT 0
 ,[RWegRoot] integer DEFAULT 0
 ,[RWegMwst] integer DEFAULT 0
 ,[LastFormNr] integer DEFAULT 0
 ,[DrkFlags1] integer DEFAULT 0
 ,[DrkFlags2] integer DEFAULT 0
 ,[AnzEPAnt] integer DEFAULT 0
 ,[BezEPAnt1] varchar(20) DEFAULT ''
 ,[BezEPAnt2] varchar(20) DEFAULT ''
 ,[BezEPAnt3] varchar(20) DEFAULT ''
 ,[BezEPAnt4] varchar(20) DEFAULT ''
 ,[BezEPAnt5] varchar(20) DEFAULT ''
 ,[BezEPAnt6] varchar(20) DEFAULT ''
 ,[BezZeit] varchar(20) DEFAULT ''
 ,[EpAnteile] char(12) DEFAULT ''
 ,[RndGPKfm] tinyint DEFAULT 0
 ,[NavJobNo] char(20) DEFAULT ''
 ,[NavDocNo] char(20) DEFAULT ''
 ,[NavDocNo2] char(20) DEFAULT ''
 ,[NavDocNo3] char(20) DEFAULT ''
 ,[AbwVK2LH] float DEFAULT 0
 ,[AbwFaktor1] float DEFAULT 0
 ,[NavDocType] integer DEFAULT 0
 ,[NoSelect] integer DEFAULT 0
 ,[Revision] varchar(10) DEFAULT ''
 ,[Additional] varchar(20) DEFAULT ''
 ,[RefNo1] varchar(20) DEFAULT ''
 ,[RefNo2] varchar(20) DEFAULT ''
 ,[RefNo3] varchar(20) DEFAULT ''
 ,[RefNo4] varchar(20) DEFAULT ''
 ,[RefDate1] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[RefDate2] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[RefDate3] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[RefDate4] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[RefText1] varchar(50) DEFAULT ''
 ,[RefText2] varchar(50) DEFAULT ''
 ,[RefText3] varchar(50) DEFAULT ''
 ,[RefText4] varchar(50) DEFAULT ''
 ,[DictPlane] integer DEFAULT 0
 ,[ONLB_Bez] varchar(60) DEFAULT ''
 ,[ONLB_Name] varchar(60) DEFAULT ''
 ,[ONLB_Kenn] char(10) DEFAULT ''
 ,[ONLB_Vers] integer DEFAULT 0
 ,[ONLB_Date] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[ONLB_Frei] tinyint DEFAULT 0
 ,[StampXml] char(32) DEFAULT ''
 ,[StampHtml] char(32) DEFAULT ''
 ,[BT10] varchar(30) DEFAULT ''
 ,[BT11] varchar(30) DEFAULT ''
 ,[BT12] varchar(30) DEFAULT ''
 ,[BT13] varchar(30) DEFAULT ''
 ,[BT14] varchar(30) DEFAULT ''
 ,[BT17] varchar(30) DEFAULT ''
 ,[BT18] varchar(30) DEFAULT ''
 ,[BT71] varchar(30) DEFAULT ''
 ,[BT19] varchar(50) DEFAULT ''
 ,[OzFormel] varchar(80) DEFAULT ''
  CONSTRAINT [Pk_BelKopfExt]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO

-- drop obsolete triggers and the triggered table with keyvalues
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelKopfExt_KeyDel')
  DROP TRIGGER [dbo].[tr_BelKopfExt_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelKopfExt_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelKopfExt_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelKopfExt_Keys')
  DROP TABLE [dbo].[ut_BelKopfExt_Keys]
GO

-- add new fields
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] 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_BelKopfExt' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] 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_BelKopfExt' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] 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_BelKopfExt' and sc.[name] = 'NkMengen')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NkMengen] 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_BelKopfExt' and sc.[name] = 'Lose')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Lose] 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_BelKopfExt' and sc.[name] = 'GaebOz')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GaebOz] char(9) 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_BelKopfExt' and sc.[name] = 'GaebDvNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GaebDvNr] varchar(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_BelKopfExt' and sc.[name] = 'GaebBietNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GaebBietNr] varchar(3) 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_BelKopfExt' and sc.[name] = 'GaebVergNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GaebVergNr] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Untertitel')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Untertitel] 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_BelKopfExt' and sc.[name] = 'ZuschFrist')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ZuschFrist] 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_BelKopfExt' and sc.[name] = 'SubZeit')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [SubZeit] char(5) 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_BelKopfExt' and sc.[name] = 'GaebLVBez')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GaebLVBez] varchar(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_BelKopfExt' and sc.[name] = 'RwegSkonto')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RwegSkonto] 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_BelKopfExt' and sc.[name] = 'LagerVerbu')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [LagerVerbu] 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_BelKopfExt' and sc.[name] = 'NewRwSusp')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NewRwSusp] 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_BelKopfExt' and sc.[name] = 'CxLstgPos')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CxLstgPos] 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_BelKopfExt' and sc.[name] = 'CxTextPos')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CxTextPos] 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_BelKopfExt' and sc.[name] = 'CxVtNtPos')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CxVtNtPos] 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_BelKopfExt' and sc.[name] = 'CxAufmass')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CxAufmass] 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_BelKopfExt' and sc.[name] = 'bFormKeys')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [bFormKeys] 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_BelKopfExt' and sc.[name] = 'FormKeyFi')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [FormKeyFi] 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_BelKopfExt' and sc.[name] = 'Floskeln')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Floskeln] 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_BelKopfExt' and sc.[name] = 'GAEBArtMo')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [GAEBArtMo] 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_BelKopfExt' and sc.[name] = 'NrHwGC')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NrHwGC] char(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SuSpOpts')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [SuSpOpts] char(140) 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_BelKopfExt' and sc.[name] = 'CuPreis')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CuPreis] 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_BelKopfExt' and sc.[name] = 'CalcEk2Vk')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CalcEk2Vk] 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_BelKopfExt' and sc.[name] = 'CalcAuf2Vk')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CalcAuf2Vk] 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_BelKopfExt' and sc.[name] = 'CalcNEP')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [CalcNEP] 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_BelKopfExt' and sc.[name] = 'ProgVers')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ProgVers] 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_BelKopfExt' and sc.[name] = 'Sum_Netto')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Sum_Netto] 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_BelKopfExt' and sc.[name] = 'Sum_Gesamt')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Sum_Gesamt] 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_BelKopfExt' and sc.[name] = 'Sum_Mwst')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Sum_Mwst] 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_BelKopfExt' and sc.[name] = 'Sum_NettoB')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Sum_NettoB] 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_BelKopfExt' and sc.[name] = 'ZUAB_BRUTTO')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ZUAB_BRUTTO] 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_BelKopfExt' and sc.[name] = 'LVNETTO')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [LVNETTO] 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_BelKopfExt' and sc.[name] = 'LVMWST')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [LVMWST] 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_BelKopfExt' and sc.[name] = 'LVBRUTTO')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [LVBRUTTO] 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_BelKopfExt' and sc.[name] = 'TRNet')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRNet] 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_BelKopfExt' and sc.[name] = 'TRMws')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRMws] 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_BelKopfExt' and sc.[name] = 'TRBru')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRBru] 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_BelKopfExt' and sc.[name] = 'TRNet_BEZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRNet_BEZ] 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_BelKopfExt' and sc.[name] = 'TRMws_BEZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRMws_BEZ] 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_BelKopfExt' and sc.[name] = 'TRBru_BEZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [TRBru_BEZ] 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_BelKopfExt' and sc.[name] = 'SkontoBasis')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [SkontoBasis] 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_BelKopfExt' and sc.[name] = 'RWegRoot')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RWegRoot] 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_BelKopfExt' and sc.[name] = 'RWegMwst')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RWegMwst] 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_BelKopfExt' and sc.[name] = 'LastFormNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [LastFormNr] 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_BelKopfExt' and sc.[name] = 'DrkFlags1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [DrkFlags1] 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_BelKopfExt' and sc.[name] = 'DrkFlags2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [DrkFlags2] 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_BelKopfExt' and sc.[name] = 'AnzEPAnt')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [AnzEPAnt] 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_BelKopfExt' and sc.[name] = 'BezEPAnt1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt1] varchar(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_BelKopfExt' and sc.[name] = 'BezEPAnt2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt2] varchar(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_BelKopfExt' and sc.[name] = 'BezEPAnt3')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt3] varchar(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_BelKopfExt' and sc.[name] = 'BezEPAnt4')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt4] varchar(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_BelKopfExt' and sc.[name] = 'BezEPAnt5')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt5] varchar(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_BelKopfExt' and sc.[name] = 'BezEPAnt6')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezEPAnt6] varchar(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_BelKopfExt' and sc.[name] = 'BezZeit')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BezZeit] varchar(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_BelKopfExt' and sc.[name] = 'EpAnteile')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [EpAnteile] 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_BelKopfExt' and sc.[name] = 'RndGPKfm')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RndGPKfm] 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_BelKopfExt' and sc.[name] = 'NavJobNo')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NavJobNo] 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_BelKopfExt' and sc.[name] = 'NavDocNo')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NavDocNo] 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_BelKopfExt' and sc.[name] = 'NavDocNo2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NavDocNo2] 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_BelKopfExt' and sc.[name] = 'NavDocNo3')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NavDocNo3] 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_BelKopfExt' and sc.[name] = 'AbwVK2LH')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [AbwVK2LH] 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_BelKopfExt' and sc.[name] = 'AbwFaktor1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [AbwFaktor1] 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_BelKopfExt' and sc.[name] = 'NavDocType')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NavDocType] 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_BelKopfExt' and sc.[name] = 'NoSelect')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [NoSelect] 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_BelKopfExt' and sc.[name] = 'Revision')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Revision] varchar(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_BelKopfExt' and sc.[name] = 'Additional')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [Additional] varchar(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_BelKopfExt' and sc.[name] = 'RefNo1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefNo1] varchar(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_BelKopfExt' and sc.[name] = 'RefNo2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefNo2] varchar(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_BelKopfExt' and sc.[name] = 'RefNo3')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefNo3] varchar(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_BelKopfExt' and sc.[name] = 'RefNo4')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefNo4] varchar(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_BelKopfExt' and sc.[name] = 'RefDate1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefDate1] 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_BelKopfExt' and sc.[name] = 'RefDate2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefDate2] 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_BelKopfExt' and sc.[name] = 'RefDate3')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefDate3] 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_BelKopfExt' and sc.[name] = 'RefDate4')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefDate4] 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_BelKopfExt' and sc.[name] = 'RefText1')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefText1] varchar(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_BelKopfExt' and sc.[name] = 'RefText2')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefText2] varchar(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_BelKopfExt' and sc.[name] = 'RefText3')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefText3] varchar(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_BelKopfExt' and sc.[name] = 'RefText4')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [RefText4] varchar(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_BelKopfExt' and sc.[name] = 'DictPlane')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [DictPlane] 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_BelKopfExt' and sc.[name] = 'ONLB_Bez')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Bez] varchar(60) 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_BelKopfExt' and sc.[name] = 'ONLB_Name')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Name] varchar(60) 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_BelKopfExt' and sc.[name] = 'ONLB_Kenn')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Kenn] 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_BelKopfExt' and sc.[name] = 'ONLB_Vers')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Vers] 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_BelKopfExt' and sc.[name] = 'ONLB_Date')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Date] 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_BelKopfExt' and sc.[name] = 'ONLB_Frei')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [ONLB_Frei] 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_BelKopfExt' and sc.[name] = 'StampXml')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [StampXml] char(32) 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_BelKopfExt' and sc.[name] = 'StampHtml')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [StampHtml] char(32) 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_BelKopfExt' and sc.[name] = 'BT10')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT10] varchar(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_BelKopfExt' and sc.[name] = 'BT11')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT11] varchar(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_BelKopfExt' and sc.[name] = 'BT12')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT12] varchar(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_BelKopfExt' and sc.[name] = 'BT13')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT13] varchar(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_BelKopfExt' and sc.[name] = 'BT14')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT14] varchar(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_BelKopfExt' and sc.[name] = 'BT17')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT17] varchar(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_BelKopfExt' and sc.[name] = 'BT18')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT18] varchar(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_BelKopfExt' and sc.[name] = 'BT71')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT71] varchar(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_BelKopfExt' and sc.[name] = 'BT19')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [BT19] varchar(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_BelKopfExt' and sc.[name] = 'OzFormel')
BEGIN
  ALTER TABLE [dbo].[ut_BelKopfExt] ADD [OzFormel] varchar(80) NOT NULL DEFAULT ''
END
GO

-- check lengths of text fields
IF (8 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'PrjNr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'PrjNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [PrjNr] char(8)
END
GO
IF (8 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'PrjNr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'PrjNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [PrjNr] varchar(8)
END
GO
IF (2 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelArt'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelArt'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BelArt] char(2)
END
GO
IF (2 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelArt'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelArt'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BelArt] varchar(2)
END
GO
IF (8 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelNr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BelNr] char(8)
END
GO
IF (8 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelNr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BelNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BelNr] varchar(8)
END
GO
IF (9 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebOz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebOz'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebOz] char(9)
END
GO
IF (9 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebOz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebOz'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebOz] varchar(9)
END
GO
IF (8 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebDvNr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebDvNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebDvNr] char(8)
END
GO
IF (8 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebDvNr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebDvNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebDvNr] varchar(8)
END
GO
IF (3 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebBietNr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebBietNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebBietNr] char(3)
END
GO
IF (3 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebBietNr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebBietNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebBietNr] varchar(3)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebVergNr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebVergNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebVergNr] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebVergNr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebVergNr'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebVergNr] varchar(15)
END
GO
IF (5 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SubZeit'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SubZeit'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [SubZeit] char(5)
END
GO
IF (5 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SubZeit'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SubZeit'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [SubZeit] varchar(5)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebLVBez'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebLVBez'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebLVBez] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebLVBez'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'GaebLVBez'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [GaebLVBez] varchar(40)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'FormKeyFi'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'FormKeyFi'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [FormKeyFi] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'FormKeyFi'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'FormKeyFi'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [FormKeyFi] varchar(30)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NrHwGC'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NrHwGC'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NrHwGC] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NrHwGC'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NrHwGC'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NrHwGC] varchar(15)
END
GO
IF (140 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SuSpOpts'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SuSpOpts'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [SuSpOpts] char(140)
END
GO
IF (140 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SuSpOpts'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'SuSpOpts'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [SuSpOpts] varchar(140)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt1] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt1] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt2] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt2] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt3] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt3] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt4'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt4] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt4'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt4] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt5'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt5'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt5] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt5'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt5'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt5] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt6'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt6'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt6] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt6'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezEPAnt6'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezEPAnt6] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezZeit'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezZeit'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezZeit] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezZeit'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BezZeit'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BezZeit] varchar(20)
END
GO
IF (12 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'EpAnteile'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'EpAnteile'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [EpAnteile] char(12)
END
GO
IF (12 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'EpAnteile'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'EpAnteile'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [EpAnteile] varchar(12)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavJobNo'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavJobNo'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavJobNo] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavJobNo'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavJobNo'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavJobNo] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo2] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo2] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo3] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'NavDocNo3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [NavDocNo3] varchar(20)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Revision'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Revision'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [Revision] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Revision'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Revision'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [Revision] varchar(10)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Additional'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Additional'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [Additional] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Additional'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'Additional'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [Additional] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo1] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo1] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo2] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo2] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo3] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo3] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo4'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo4] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo4'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefNo4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefNo4] varchar(20)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText1] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText1'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText1] varchar(50)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText2] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText2'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText2] varchar(50)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText3] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText3'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText3] varchar(50)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText4'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText4] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText4'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'RefText4'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [RefText4] varchar(50)
END
GO
IF (60 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Bez'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Bez'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Bez] char(60)
END
GO
IF (60 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Bez'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Bez'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Bez] varchar(60)
END
GO
IF (60 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Name'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Name'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Name] char(60)
END
GO
IF (60 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Name'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Name'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Name] varchar(60)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Kenn'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Kenn'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Kenn] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Kenn'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'ONLB_Kenn'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [ONLB_Kenn] varchar(10)
END
GO
IF (32 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampXml'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampXml'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [StampXml] char(32)
END
GO
IF (32 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampXml'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampXml'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [StampXml] varchar(32)
END
GO
IF (32 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampHtml'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampHtml'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [StampHtml] char(32)
END
GO
IF (32 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampHtml'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'StampHtml'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [StampHtml] varchar(32)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT10'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT10'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT10] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT10'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT10'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT10] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT11'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT11'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT11] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT11'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT11'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT11] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT12'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT12'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT12] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT12'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT12'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT12] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT13'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT13'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT13] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT13'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT13'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT13] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT14'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT14'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT14] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT14'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT14'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT14] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT17'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT17'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT17] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT17'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT17'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT17] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT18'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT18'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT18] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT18'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT18'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT18] varchar(30)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT71'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT71'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT71] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT71'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT71'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT71] varchar(30)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT19'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT19'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT19] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT19'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'BT19'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [BT19] varchar(50)
END
GO
IF (80 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'OzFormel'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'OzFormel'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [OzFormel] char(80)
END
GO
IF (80 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'OzFormel'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_BelKopfExt' and sc.[name] = 'OzFormel'))
BEGIN
   ALTER TABLE [dbo].[ut_BelKopfExt] ALTER COLUMN [OzFormel] varchar(80)
END
GO

-- create dedicated view
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelKopfExt')
  DROP VIEW [dbo].[BelKopfExt]
GO
CREATE VIEW [dbo].[BelKopfExt] AS
  SELECT [RecId]
 ,[PrjNr]
 ,[BelArt]
 ,[BelNr]
 ,[NkMengen]
 ,[Lose]
 ,[GaebOz]
 ,[GaebDvNr]
 ,[GaebBietNr]
 ,[GaebVergNr]
 ,[Untertitel]
 ,[ZuschFrist]
 ,[SubZeit]
 ,[GaebLVBez]
 ,[RwegSkonto]
 ,[LagerVerbu]
 ,[NewRwSusp]
 ,[CxLstgPos]
 ,[CxTextPos]
 ,[CxVtNtPos]
 ,[CxAufmass]
 ,[bFormKeys]
 ,[FormKeyFi]
 ,[Floskeln]
 ,[GAEBArtMo]
 ,[NrHwGC]
 ,[SuSpOpts]
 ,[CuPreis]
 ,[CalcEk2Vk]
 ,[CalcAuf2Vk]
 ,[CalcNEP]
 ,[ProgVers]
 ,[Sum_Netto]
 ,[Sum_Gesamt]
 ,[Sum_Mwst]
 ,[Sum_NettoB]
 ,[ZUAB_BRUTTO]
 ,[LVNETTO]
 ,[LVMWST]
 ,[LVBRUTTO]
 ,[TRNet]
 ,[TRMws]
 ,[TRBru]
 ,[TRNet_BEZ]
 ,[TRMws_BEZ]
 ,[TRBru_BEZ]
 ,[SkontoBasis]
 ,[RWegRoot]
 ,[RWegMwst]
 ,[LastFormNr]
 ,[DrkFlags1]
 ,[DrkFlags2]
 ,[AnzEPAnt]
 ,[BezEPAnt1]
 ,[BezEPAnt2]
 ,[BezEPAnt3]
 ,[BezEPAnt4]
 ,[BezEPAnt5]
 ,[BezEPAnt6]
 ,[BezZeit]
 ,[EpAnteile]
 ,[RndGPKfm]
 ,[NavJobNo]
 ,[NavDocNo]
 ,[NavDocNo2]
 ,[NavDocNo3]
 ,[AbwVK2LH]
 ,[AbwFaktor1]
 ,[NavDocType]
 ,[NoSelect]
 ,[Revision]
 ,[Additional]
 ,[RefNo1]
 ,[RefNo2]
 ,[RefNo3]
 ,[RefNo4]
 ,[RefDate1]
 ,[RefDate2]
 ,[RefDate3]
 ,[RefDate4]
 ,[RefText1]
 ,[RefText2]
 ,[RefText3]
 ,[RefText4]
 ,[DictPlane]
 ,[ONLB_Bez]
 ,[ONLB_Name]
 ,[ONLB_Kenn]
 ,[ONLB_Vers]
 ,[ONLB_Date]
 ,[ONLB_Frei]
 ,[StampXml]
 ,[StampHtml]
 ,[BT10]
 ,[BT11]
 ,[BT12]
 ,[BT13]
 ,[BT14]
 ,[BT17]
 ,[BT18]
 ,[BT71]
 ,[BT19]
 ,[OzFormel]
  FROM [dbo].[ut_BelKopfExt]
GO


-- create function to get the next RecId
IF OBJECT_ID (N'itcfunc_NextRecId_BelKopfExt', N'FN') IS NOT NULL
  DROP FUNCTION dbo.itcfunc_NextRecId_BelKopfExt
GO
CREATE FUNCTION dbo.itcfunc_NextRecId_BelKopfExt() RETURNS integer
AS
BEGIN
  RETURN isnull((SELECT MAX(RecId) FROM [dbo].[ut_BelKopfExt] WITH (READUNCOMMITTED)),0) + 1
END
GO

-- select with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Sel_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelKopfExt]  @mRI integer
AS
  SELECT
    [PrjNr]
   ,[BelArt]
   ,[BelNr]
   ,[NkMengen]
   ,[Lose]
   ,[GaebOz]
   ,[GaebDvNr]
   ,[GaebBietNr]
   ,[GaebVergNr]
   ,[Untertitel]
   ,[ZuschFrist]
   ,[SubZeit]
   ,[GaebLVBez]
   ,[RwegSkonto]
   ,[LagerVerbu]
   ,[NewRwSusp]
   ,[CxLstgPos]
   ,[CxTextPos]
   ,[CxVtNtPos]
   ,[CxAufmass]
   ,[bFormKeys]
   ,[FormKeyFi]
   ,[Floskeln]
   ,[GAEBArtMo]
   ,[NrHwGC]
   ,[SuSpOpts]
   ,[CuPreis]
   ,[CalcEk2Vk]
   ,[CalcAuf2Vk]
   ,[CalcNEP]
   ,[ProgVers]
   ,[Sum_Netto]
   ,[Sum_Gesamt]
   ,[Sum_Mwst]
   ,[Sum_NettoB]
   ,[ZUAB_BRUTTO]
   ,[LVNETTO]
   ,[LVMWST]
   ,[LVBRUTTO]
   ,[TRNet]
   ,[TRMws]
   ,[TRBru]
   ,[TRNet_BEZ]
   ,[TRMws_BEZ]
   ,[TRBru_BEZ]
   ,[SkontoBasis]
   ,[RWegRoot]
   ,[RWegMwst]
   ,[LastFormNr]
   ,[DrkFlags1]
   ,[DrkFlags2]
   ,[AnzEPAnt]
   ,[BezEPAnt1]
   ,[BezEPAnt2]
   ,[BezEPAnt3]
   ,[BezEPAnt4]
   ,[BezEPAnt5]
   ,[BezEPAnt6]
   ,[BezZeit]
   ,[EpAnteile]
   ,[RndGPKfm]
   ,[NavJobNo]
   ,[NavDocNo]
   ,[NavDocNo2]
   ,[NavDocNo3]
   ,[AbwVK2LH]
   ,[AbwFaktor1]
   ,[NavDocType]
   ,[NoSelect]
   ,[Revision]
   ,[Additional]
   ,[RefNo1]
   ,[RefNo2]
   ,[RefNo3]
   ,[RefNo4]
   ,[RefDate1]
   ,[RefDate2]
   ,[RefDate3]
   ,[RefDate4]
   ,[RefText1]
   ,[RefText2]
   ,[RefText3]
   ,[RefText4]
   ,[DictPlane]
   ,[ONLB_Bez]
   ,[ONLB_Name]
   ,[ONLB_Kenn]
   ,[ONLB_Vers]
   ,[ONLB_Date]
   ,[ONLB_Frei]
   ,[StampXml]
   ,[StampHtml]
   ,[BT10]
   ,[BT11]
   ,[BT12]
   ,[BT13]
   ,[BT14]
   ,[BT17]
   ,[BT18]
   ,[BT71]
   ,[BT19]
   ,[OzFormel]
  FROM [dbo].[ut_BelKopfExt] WHERE RecId = @mRI
GO

-- select with modern clients
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel2_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Sel2_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Sel2_BelKopfExt]  @Param_RecId varchar(20)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)
  SELECT * FROM [dbo].[BelKopfExt] WHERE RecId = @mRI
GO

-- insert with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Append_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Append_BelKopfExt]
   @Param_PrjNr char(8)
  ,@Param_BelArt char(2)
  ,@Param_BelNr char(8)
  ,@Param_NkMengen integer
  ,@Param_Lose tinyint
  ,@Param_GaebOz char(9)
  ,@Param_GaebDvNr varchar(8)
  ,@Param_GaebBietNr varchar(3)
  ,@Param_GaebVergNr varchar(15)
  ,@Param_Untertitel integer
  ,@Param_ZuschFrist datetime
  ,@Param_SubZeit char(5)
  ,@Param_GaebLVBez varchar(40)
  ,@Param_RwegSkonto integer
  ,@Param_LagerVerbu tinyint
  ,@Param_NewRwSusp tinyint
  ,@Param_CxLstgPos integer
  ,@Param_CxTextPos integer
  ,@Param_CxVtNtPos integer
  ,@Param_CxAufmass integer
  ,@Param_bFormKeys tinyint
  ,@Param_FormKeyFi char(30)
  ,@Param_Floskeln integer
  ,@Param_GAEBArtMo tinyint
  ,@Param_NrHwGC char(15)
  ,@Param_SuSpOpts char(140)
  ,@Param_CuPreis float
  ,@Param_CalcEk2Vk tinyint
  ,@Param_CalcAuf2Vk tinyint
  ,@Param_CalcNEP tinyint
  ,@Param_ProgVers integer
  ,@Param_Sum_Netto float
  ,@Param_Sum_Gesamt float
  ,@Param_Sum_Mwst float
  ,@Param_Sum_NettoB float
  ,@Param_ZUAB_BRUTTO float
  ,@Param_LVNETTO float
  ,@Param_LVMWST float
  ,@Param_LVBRUTTO float
  ,@Param_TRNet float
  ,@Param_TRMws float
  ,@Param_TRBru float
  ,@Param_TRNet_BEZ float
  ,@Param_TRMws_BEZ float
  ,@Param_TRBru_BEZ float
  ,@Param_SkontoBasis float
  ,@Param_RWegRoot integer
  ,@Param_RWegMwst integer
  ,@Param_LastFormNr integer
  ,@Param_DrkFlags1 integer
  ,@Param_DrkFlags2 integer
  ,@Param_AnzEPAnt integer
  ,@Param_BezEPAnt1 varchar(20)
  ,@Param_BezEPAnt2 varchar(20)
  ,@Param_BezEPAnt3 varchar(20)
  ,@Param_BezEPAnt4 varchar(20)
  ,@Param_BezEPAnt5 varchar(20)
  ,@Param_BezEPAnt6 varchar(20)
  ,@Param_BezZeit varchar(20)
  ,@Param_EpAnteile char(12)
  ,@Param_RndGPKfm tinyint
  ,@Param_NavJobNo char(20)
  ,@Param_NavDocNo char(20)
  ,@Param_NavDocNo2 char(20)
  ,@Param_NavDocNo3 char(20)
  ,@Param_AbwVK2LH float
  ,@Param_AbwFaktor1 float
  ,@Param_NavDocType integer
  ,@Param_NoSelect integer
  ,@Param_Revision varchar(10)
  ,@Param_Additional varchar(20)
  ,@Param_RefNo1 varchar(20)
  ,@Param_RefNo2 varchar(20)
  ,@Param_RefNo3 varchar(20)
  ,@Param_RefNo4 varchar(20)
  ,@Param_RefDate1 datetime
  ,@Param_RefDate2 datetime
  ,@Param_RefDate3 datetime
  ,@Param_RefDate4 datetime
  ,@Param_RefText1 varchar(50)
  ,@Param_RefText2 varchar(50)
  ,@Param_RefText3 varchar(50)
  ,@Param_RefText4 varchar(50)
  ,@Param_DictPlane integer
  ,@Param_ONLB_Bez varchar(60)
  ,@Param_ONLB_Name varchar(60)
  ,@Param_ONLB_Kenn char(10)
  ,@Param_ONLB_Vers integer
  ,@Param_ONLB_Date datetime
  ,@Param_ONLB_Frei tinyint
  ,@Param_StampXml char(32)
  ,@Param_StampHtml char(32)
  ,@Param_BT10 varchar(30)
  ,@Param_BT11 varchar(30)
  ,@Param_BT12 varchar(30)
  ,@Param_BT13 varchar(30)
  ,@Param_BT14 varchar(30)
  ,@Param_BT17 varchar(30)
  ,@Param_BT18 varchar(30)
  ,@Param_BT71 varchar(30)
  ,@Param_BT19 varchar(50)
  ,@Param_OzFormel varchar(80)
AS
  DECLARE @NeueId integer
  DECLARE @m_CountDown integer = 10
  WHILE @m_CountDown > 0 BEGIN
    BEGIN TRANSACTION
    BEGIN TRY
      SET @NeueId = dbo.itcfunc_NextRecId_BelKopfExt()
      INSERT INTO [dbo].[ut_BelKopfExt] (RecId
        ,[PrjNr]
        ,[BelArt]
        ,[BelNr]
        ,[NkMengen]
        ,[Lose]
        ,[GaebOz]
        ,[GaebDvNr]
        ,[GaebBietNr]
        ,[GaebVergNr]
        ,[Untertitel]
        ,[ZuschFrist]
        ,[SubZeit]
        ,[GaebLVBez]
        ,[RwegSkonto]
        ,[LagerVerbu]
        ,[NewRwSusp]
        ,[CxLstgPos]
        ,[CxTextPos]
        ,[CxVtNtPos]
        ,[CxAufmass]
        ,[bFormKeys]
        ,[FormKeyFi]
        ,[Floskeln]
        ,[GAEBArtMo]
        ,[NrHwGC]
        ,[SuSpOpts]
        ,[CuPreis]
        ,[CalcEk2Vk]
        ,[CalcAuf2Vk]
        ,[CalcNEP]
        ,[ProgVers]
        ,[Sum_Netto]
        ,[Sum_Gesamt]
        ,[Sum_Mwst]
        ,[Sum_NettoB]
        ,[ZUAB_BRUTTO]
        ,[LVNETTO]
        ,[LVMWST]
        ,[LVBRUTTO]
        ,[TRNet]
        ,[TRMws]
        ,[TRBru]
        ,[TRNet_BEZ]
        ,[TRMws_BEZ]
        ,[TRBru_BEZ]
        ,[SkontoBasis]
        ,[RWegRoot]
        ,[RWegMwst]
        ,[LastFormNr]
        ,[DrkFlags1]
        ,[DrkFlags2]
        ,[AnzEPAnt]
        ,[BezEPAnt1]
        ,[BezEPAnt2]
        ,[BezEPAnt3]
        ,[BezEPAnt4]
        ,[BezEPAnt5]
        ,[BezEPAnt6]
        ,[BezZeit]
        ,[EpAnteile]
        ,[RndGPKfm]
        ,[NavJobNo]
        ,[NavDocNo]
        ,[NavDocNo2]
        ,[NavDocNo3]
        ,[AbwVK2LH]
        ,[AbwFaktor1]
        ,[NavDocType]
        ,[NoSelect]
        ,[Revision]
        ,[Additional]
        ,[RefNo1]
        ,[RefNo2]
        ,[RefNo3]
        ,[RefNo4]
        ,[RefDate1]
        ,[RefDate2]
        ,[RefDate3]
        ,[RefDate4]
        ,[RefText1]
        ,[RefText2]
        ,[RefText3]
        ,[RefText4]
        ,[DictPlane]
        ,[ONLB_Bez]
        ,[ONLB_Name]
        ,[ONLB_Kenn]
        ,[ONLB_Vers]
        ,[ONLB_Date]
        ,[ONLB_Frei]
        ,[StampXml]
        ,[StampHtml]
        ,[BT10]
        ,[BT11]
        ,[BT12]
        ,[BT13]
        ,[BT14]
        ,[BT17]
        ,[BT18]
        ,[BT71]
        ,[BT19]
        ,[OzFormel]
          ) VALUES (@NeueId
        ,UPPER(RTRIM(@Param_PrjNr))
        ,UPPER(RTRIM(@Param_BelArt))
        ,UPPER(RTRIM(@Param_BelNr))
        ,@Param_NkMengen
        ,@Param_Lose
        ,RTRIM(@Param_GaebOz)
        ,RTRIM(@Param_GaebDvNr)
        ,RTRIM(@Param_GaebBietNr)
        ,RTRIM(@Param_GaebVergNr)
        ,@Param_Untertitel
        ,@Param_ZuschFrist
        ,UPPER(RTRIM(@Param_SubZeit))
        ,RTRIM(@Param_GaebLVBez)
        ,@Param_RwegSkonto
        ,@Param_LagerVerbu
        ,@Param_NewRwSusp
        ,@Param_CxLstgPos
        ,@Param_CxTextPos
        ,@Param_CxVtNtPos
        ,@Param_CxAufmass
        ,@Param_bFormKeys
        ,RTRIM(@Param_FormKeyFi)
        ,@Param_Floskeln
        ,@Param_GAEBArtMo
        ,UPPER(RTRIM(@Param_NrHwGC))
        ,UPPER(RTRIM(@Param_SuSpOpts))
        ,@Param_CuPreis
        ,@Param_CalcEk2Vk
        ,@Param_CalcAuf2Vk
        ,@Param_CalcNEP
        ,@Param_ProgVers
        ,@Param_Sum_Netto
        ,@Param_Sum_Gesamt
        ,@Param_Sum_Mwst
        ,@Param_Sum_NettoB
        ,@Param_ZUAB_BRUTTO
        ,@Param_LVNETTO
        ,@Param_LVMWST
        ,@Param_LVBRUTTO
        ,@Param_TRNet
        ,@Param_TRMws
        ,@Param_TRBru
        ,@Param_TRNet_BEZ
        ,@Param_TRMws_BEZ
        ,@Param_TRBru_BEZ
        ,@Param_SkontoBasis
        ,@Param_RWegRoot
        ,@Param_RWegMwst
        ,@Param_LastFormNr
        ,@Param_DrkFlags1
        ,@Param_DrkFlags2
        ,@Param_AnzEPAnt
        ,RTRIM(@Param_BezEPAnt1)
        ,RTRIM(@Param_BezEPAnt2)
        ,RTRIM(@Param_BezEPAnt3)
        ,RTRIM(@Param_BezEPAnt4)
        ,RTRIM(@Param_BezEPAnt5)
        ,RTRIM(@Param_BezEPAnt6)
        ,RTRIM(@Param_BezZeit)
        ,RTRIM(@Param_EpAnteile)
        ,@Param_RndGPKfm
        ,UPPER(RTRIM(@Param_NavJobNo))
        ,UPPER(RTRIM(@Param_NavDocNo))
        ,UPPER(RTRIM(@Param_NavDocNo2))
        ,UPPER(RTRIM(@Param_NavDocNo3))
        ,@Param_AbwVK2LH
        ,@Param_AbwFaktor1
        ,@Param_NavDocType
        ,@Param_NoSelect
        ,RTRIM(@Param_Revision)
        ,RTRIM(@Param_Additional)
        ,RTRIM(@Param_RefNo1)
        ,RTRIM(@Param_RefNo2)
        ,RTRIM(@Param_RefNo3)
        ,RTRIM(@Param_RefNo4)
        ,@Param_RefDate1
        ,@Param_RefDate2
        ,@Param_RefDate3
        ,@Param_RefDate4
        ,RTRIM(@Param_RefText1)
        ,RTRIM(@Param_RefText2)
        ,RTRIM(@Param_RefText3)
        ,RTRIM(@Param_RefText4)
        ,@Param_DictPlane
        ,RTRIM(@Param_ONLB_Bez)
        ,RTRIM(@Param_ONLB_Name)
        ,UPPER(RTRIM(@Param_ONLB_Kenn))
        ,@Param_ONLB_Vers
        ,@Param_ONLB_Date
        ,@Param_ONLB_Frei
        ,UPPER(RTRIM(@Param_StampXml))
        ,UPPER(RTRIM(@Param_StampHtml))
        ,RTRIM(@Param_BT10)
        ,RTRIM(@Param_BT11)
        ,RTRIM(@Param_BT12)
        ,RTRIM(@Param_BT13)
        ,RTRIM(@Param_BT14)
        ,RTRIM(@Param_BT17)
        ,RTRIM(@Param_BT18)
        ,RTRIM(@Param_BT71)
        ,RTRIM(@Param_BT19)
        ,RTRIM(@Param_OzFormel)
          )
      COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
      ROLLBACK TRANSACTION
      SET @NeueId = 0
    END CATCH

    IF @NeueId <> 0
      SET @m_CountDown = 0
    ELSE
      SET @m_CountDown = @m_CountDown - 1

    IF @m_CountDown > 0
      WAITFOR DELAY '00:00:00.050'
  END -- WHILE
  SELECT @NeueId AS RecId
GO

-- insert with obsolete clients
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Add_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Add_BelKopfExt]
AS
  DECLARE @NeueId integer = dbo.itcfunc_NextRecId_BelKopfExt()
  INSERT INTO [dbo].[ut_BelKopfExt] (RecId) VALUES( @NeueId )
  IF @@ERROR = 0
    SELECT @NeueId AS RecId
  ELSE
    SELECT 0 AS RecId
GO

-- update with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Upd_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelKopfExt] @mRI integer
  ,@Param_PrjNr char(8)
  ,@Param_BelArt char(2)
  ,@Param_BelNr char(8)
  ,@Param_NkMengen integer
  ,@Param_Lose tinyint
  ,@Param_GaebOz char(9)
  ,@Param_GaebDvNr varchar(8)
  ,@Param_GaebBietNr varchar(3)
  ,@Param_GaebVergNr varchar(15)
  ,@Param_Untertitel integer
  ,@Param_ZuschFrist datetime
  ,@Param_SubZeit char(5)
  ,@Param_GaebLVBez varchar(40)
  ,@Param_RwegSkonto integer
  ,@Param_LagerVerbu tinyint
  ,@Param_NewRwSusp tinyint
  ,@Param_CxLstgPos integer
  ,@Param_CxTextPos integer
  ,@Param_CxVtNtPos integer
  ,@Param_CxAufmass integer
  ,@Param_bFormKeys tinyint
  ,@Param_FormKeyFi char(30)
  ,@Param_Floskeln integer
  ,@Param_GAEBArtMo tinyint
  ,@Param_NrHwGC char(15)
  ,@Param_SuSpOpts char(140)
  ,@Param_CuPreis float
  ,@Param_CalcEk2Vk tinyint
  ,@Param_CalcAuf2Vk tinyint
  ,@Param_CalcNEP tinyint
  ,@Param_ProgVers integer
  ,@Param_Sum_Netto float
  ,@Param_Sum_Gesamt float
  ,@Param_Sum_Mwst float
  ,@Param_Sum_NettoB float
  ,@Param_ZUAB_BRUTTO float
  ,@Param_LVNETTO float
  ,@Param_LVMWST float
  ,@Param_LVBRUTTO float
  ,@Param_TRNet float
  ,@Param_TRMws float
  ,@Param_TRBru float
  ,@Param_TRNet_BEZ float
  ,@Param_TRMws_BEZ float
  ,@Param_TRBru_BEZ float
  ,@Param_SkontoBasis float
  ,@Param_RWegRoot integer
  ,@Param_RWegMwst integer
  ,@Param_LastFormNr integer
  ,@Param_DrkFlags1 integer
  ,@Param_DrkFlags2 integer
  ,@Param_AnzEPAnt integer
  ,@Param_BezEPAnt1 varchar(20)
  ,@Param_BezEPAnt2 varchar(20)
  ,@Param_BezEPAnt3 varchar(20)
  ,@Param_BezEPAnt4 varchar(20)
  ,@Param_BezEPAnt5 varchar(20)
  ,@Param_BezEPAnt6 varchar(20)
  ,@Param_BezZeit varchar(20)
  ,@Param_EpAnteile char(12)
  ,@Param_RndGPKfm tinyint
  ,@Param_NavJobNo char(20)
  ,@Param_NavDocNo char(20)
  ,@Param_NavDocNo2 char(20)
  ,@Param_NavDocNo3 char(20)
  ,@Param_AbwVK2LH float
  ,@Param_AbwFaktor1 float
  ,@Param_NavDocType integer
  ,@Param_NoSelect integer
  ,@Param_Revision varchar(10)
  ,@Param_Additional varchar(20)
  ,@Param_RefNo1 varchar(20)
  ,@Param_RefNo2 varchar(20)
  ,@Param_RefNo3 varchar(20)
  ,@Param_RefNo4 varchar(20)
  ,@Param_RefDate1 datetime
  ,@Param_RefDate2 datetime
  ,@Param_RefDate3 datetime
  ,@Param_RefDate4 datetime
  ,@Param_RefText1 varchar(50)
  ,@Param_RefText2 varchar(50)
  ,@Param_RefText3 varchar(50)
  ,@Param_RefText4 varchar(50)
  ,@Param_DictPlane integer
  ,@Param_ONLB_Bez varchar(60)
  ,@Param_ONLB_Name varchar(60)
  ,@Param_ONLB_Kenn char(10)
  ,@Param_ONLB_Vers integer
  ,@Param_ONLB_Date datetime
  ,@Param_ONLB_Frei tinyint
  ,@Param_StampXml char(32)
  ,@Param_StampHtml char(32)
  ,@Param_BT10 varchar(30)
  ,@Param_BT11 varchar(30)
  ,@Param_BT12 varchar(30)
  ,@Param_BT13 varchar(30)
  ,@Param_BT14 varchar(30)
  ,@Param_BT17 varchar(30)
  ,@Param_BT18 varchar(30)
  ,@Param_BT71 varchar(30)
  ,@Param_BT19 varchar(50)
  ,@Param_OzFormel varchar(80)
AS
  UPDATE [dbo].[ut_BelKopfExt] SET
    [PrjNr] = UPPER(RTRIM(@Param_PrjNr))
   ,[BelArt] = UPPER(RTRIM(@Param_BelArt))
   ,[BelNr] = UPPER(RTRIM(@Param_BelNr))
   ,[NkMengen] = @Param_NkMengen
   ,[Lose] = @Param_Lose
   ,[GaebOz] = RTRIM(@Param_GaebOz)
   ,[GaebDvNr] = RTRIM(@Param_GaebDvNr)
   ,[GaebBietNr] = RTRIM(@Param_GaebBietNr)
   ,[GaebVergNr] = RTRIM(@Param_GaebVergNr)
   ,[Untertitel] = @Param_Untertitel
   ,[ZuschFrist] = @Param_ZuschFrist
   ,[SubZeit] = UPPER(RTRIM(@Param_SubZeit))
   ,[GaebLVBez] = RTRIM(@Param_GaebLVBez)
   ,[RwegSkonto] = @Param_RwegSkonto
   ,[LagerVerbu] = @Param_LagerVerbu
   ,[NewRwSusp] = @Param_NewRwSusp
   ,[CxLstgPos] = @Param_CxLstgPos
   ,[CxTextPos] = @Param_CxTextPos
   ,[CxVtNtPos] = @Param_CxVtNtPos
   ,[CxAufmass] = @Param_CxAufmass
   ,[bFormKeys] = @Param_bFormKeys
   ,[FormKeyFi] = RTRIM(@Param_FormKeyFi)
   ,[Floskeln] = @Param_Floskeln
   ,[GAEBArtMo] = @Param_GAEBArtMo
   ,[NrHwGC] = UPPER(RTRIM(@Param_NrHwGC))
   ,[SuSpOpts] = UPPER(RTRIM(@Param_SuSpOpts))
   ,[CuPreis] = @Param_CuPreis
   ,[CalcEk2Vk] = @Param_CalcEk2Vk
   ,[CalcAuf2Vk] = @Param_CalcAuf2Vk
   ,[CalcNEP] = @Param_CalcNEP
   ,[ProgVers] = @Param_ProgVers
   ,[Sum_Netto] = @Param_Sum_Netto
   ,[Sum_Gesamt] = @Param_Sum_Gesamt
   ,[Sum_Mwst] = @Param_Sum_Mwst
   ,[Sum_NettoB] = @Param_Sum_NettoB
   ,[ZUAB_BRUTTO] = @Param_ZUAB_BRUTTO
   ,[LVNETTO] = @Param_LVNETTO
   ,[LVMWST] = @Param_LVMWST
   ,[LVBRUTTO] = @Param_LVBRUTTO
   ,[TRNet] = @Param_TRNet
   ,[TRMws] = @Param_TRMws
   ,[TRBru] = @Param_TRBru
   ,[TRNet_BEZ] = @Param_TRNet_BEZ
   ,[TRMws_BEZ] = @Param_TRMws_BEZ
   ,[TRBru_BEZ] = @Param_TRBru_BEZ
   ,[SkontoBasis] = @Param_SkontoBasis
   ,[RWegRoot] = @Param_RWegRoot
   ,[RWegMwst] = @Param_RWegMwst
   ,[LastFormNr] = @Param_LastFormNr
   ,[DrkFlags1] = @Param_DrkFlags1
   ,[DrkFlags2] = @Param_DrkFlags2
   ,[AnzEPAnt] = @Param_AnzEPAnt
   ,[BezEPAnt1] = RTRIM(@Param_BezEPAnt1)
   ,[BezEPAnt2] = RTRIM(@Param_BezEPAnt2)
   ,[BezEPAnt3] = RTRIM(@Param_BezEPAnt3)
   ,[BezEPAnt4] = RTRIM(@Param_BezEPAnt4)
   ,[BezEPAnt5] = RTRIM(@Param_BezEPAnt5)
   ,[BezEPAnt6] = RTRIM(@Param_BezEPAnt6)
   ,[BezZeit] = RTRIM(@Param_BezZeit)
   ,[EpAnteile] = RTRIM(@Param_EpAnteile)
   ,[RndGPKfm] = @Param_RndGPKfm
   ,[NavJobNo] = UPPER(RTRIM(@Param_NavJobNo))
   ,[NavDocNo] = UPPER(RTRIM(@Param_NavDocNo))
   ,[NavDocNo2] = UPPER(RTRIM(@Param_NavDocNo2))
   ,[NavDocNo3] = UPPER(RTRIM(@Param_NavDocNo3))
   ,[AbwVK2LH] = @Param_AbwVK2LH
   ,[AbwFaktor1] = @Param_AbwFaktor1
   ,[NavDocType] = @Param_NavDocType
   ,[NoSelect] = @Param_NoSelect
   ,[Revision] = RTRIM(@Param_Revision)
   ,[Additional] = RTRIM(@Param_Additional)
   ,[RefNo1] = RTRIM(@Param_RefNo1)
   ,[RefNo2] = RTRIM(@Param_RefNo2)
   ,[RefNo3] = RTRIM(@Param_RefNo3)
   ,[RefNo4] = RTRIM(@Param_RefNo4)
   ,[RefDate1] = @Param_RefDate1
   ,[RefDate2] = @Param_RefDate2
   ,[RefDate3] = @Param_RefDate3
   ,[RefDate4] = @Param_RefDate4
   ,[RefText1] = RTRIM(@Param_RefText1)
   ,[RefText2] = RTRIM(@Param_RefText2)
   ,[RefText3] = RTRIM(@Param_RefText3)
   ,[RefText4] = RTRIM(@Param_RefText4)
   ,[DictPlane] = @Param_DictPlane
   ,[ONLB_Bez] = RTRIM(@Param_ONLB_Bez)
   ,[ONLB_Name] = RTRIM(@Param_ONLB_Name)
   ,[ONLB_Kenn] = UPPER(RTRIM(@Param_ONLB_Kenn))
   ,[ONLB_Vers] = @Param_ONLB_Vers
   ,[ONLB_Date] = @Param_ONLB_Date
   ,[ONLB_Frei] = @Param_ONLB_Frei
   ,[StampXml] = UPPER(RTRIM(@Param_StampXml))
   ,[StampHtml] = UPPER(RTRIM(@Param_StampHtml))
   ,[BT10] = RTRIM(@Param_BT10)
   ,[BT11] = RTRIM(@Param_BT11)
   ,[BT12] = RTRIM(@Param_BT12)
   ,[BT13] = RTRIM(@Param_BT13)
   ,[BT14] = RTRIM(@Param_BT14)
   ,[BT17] = RTRIM(@Param_BT17)
   ,[BT18] = RTRIM(@Param_BT18)
   ,[BT71] = RTRIM(@Param_BT71)
   ,[BT19] = RTRIM(@Param_BT19)
   ,[OzFormel] = RTRIM(@Param_OzFormel)
  WHERE RecId = @mRI
GO

-- update with modern clients
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd2_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Upd2_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Upd2_BelKopfExt] @Param_RecId varchar(20)
  ,@Param_PrjNr varchar(8)
  ,@Param_BelArt varchar(2)
  ,@Param_BelNr varchar(8)
  ,@Param_NkMengen varchar(1)
  ,@Param_Lose varchar(1)
  ,@Param_GaebOz varchar(9)
  ,@Param_GaebDvNr varchar(8)
  ,@Param_GaebBietNr varchar(3)
  ,@Param_GaebVergNr varchar(15)
  ,@Param_Untertitel varchar(1)
  ,@Param_ZuschFrist varchar(10)
  ,@Param_SubZeit varchar(5)
  ,@Param_GaebLVBez varchar(40)
  ,@Param_RwegSkonto varchar(1)
  ,@Param_LagerVerbu varchar(1)
  ,@Param_NewRwSusp varchar(1)
  ,@Param_CxLstgPos varchar(3)
  ,@Param_CxTextPos varchar(3)
  ,@Param_CxVtNtPos varchar(3)
  ,@Param_CxAufmass varchar(3)
  ,@Param_bFormKeys varchar(1)
  ,@Param_FormKeyFi varchar(30)
  ,@Param_Floskeln varchar(1)
  ,@Param_GAEBArtMo varchar(1)
  ,@Param_NrHwGC varchar(15)
  ,@Param_SuSpOpts varchar(140)
  ,@Param_CuPreis varchar(8)
  ,@Param_CalcEk2Vk varchar(1)
  ,@Param_CalcAuf2Vk varchar(1)
  ,@Param_CalcNEP varchar(1)
  ,@Param_ProgVers varchar(4)
  ,@Param_Sum_Netto varchar(14)
  ,@Param_Sum_Gesamt varchar(14)
  ,@Param_Sum_Mwst varchar(14)
  ,@Param_Sum_NettoB varchar(14)
  ,@Param_ZUAB_BRUTTO varchar(14)
  ,@Param_LVNETTO varchar(14)
  ,@Param_LVMWST varchar(14)
  ,@Param_LVBRUTTO varchar(14)
  ,@Param_TRNet varchar(14)
  ,@Param_TRMws varchar(14)
  ,@Param_TRBru varchar(14)
  ,@Param_TRNet_BEZ varchar(14)
  ,@Param_TRMws_BEZ varchar(14)
  ,@Param_TRBru_BEZ varchar(14)
  ,@Param_SkontoBasis varchar(14)
  ,@Param_RWegRoot varchar(1)
  ,@Param_RWegMwst varchar(1)
  ,@Param_LastFormNr varchar(8)
  ,@Param_DrkFlags1 varchar(8)
  ,@Param_DrkFlags2 varchar(8)
  ,@Param_AnzEPAnt varchar(1)
  ,@Param_BezEPAnt1 varchar(20)
  ,@Param_BezEPAnt2 varchar(20)
  ,@Param_BezEPAnt3 varchar(20)
  ,@Param_BezEPAnt4 varchar(20)
  ,@Param_BezEPAnt5 varchar(20)
  ,@Param_BezEPAnt6 varchar(20)
  ,@Param_BezZeit varchar(20)
  ,@Param_EpAnteile varchar(12)
  ,@Param_RndGPKfm varchar(1)
  ,@Param_NavJobNo varchar(20)
  ,@Param_NavDocNo varchar(20)
  ,@Param_NavDocNo2 varchar(20)
  ,@Param_NavDocNo3 varchar(20)
  ,@Param_AbwVK2LH varchar(8)
  ,@Param_AbwFaktor1 varchar(4)
  ,@Param_NavDocType varchar(2)
  ,@Param_NoSelect varchar(2)
  ,@Param_Revision varchar(10)
  ,@Param_Additional varchar(20)
  ,@Param_RefNo1 varchar(20)
  ,@Param_RefNo2 varchar(20)
  ,@Param_RefNo3 varchar(20)
  ,@Param_RefNo4 varchar(20)
  ,@Param_RefDate1 varchar(10)
  ,@Param_RefDate2 varchar(10)
  ,@Param_RefDate3 varchar(10)
  ,@Param_RefDate4 varchar(10)
  ,@Param_RefText1 varchar(50)
  ,@Param_RefText2 varchar(50)
  ,@Param_RefText3 varchar(50)
  ,@Param_RefText4 varchar(50)
  ,@Param_DictPlane varchar(1)
  ,@Param_ONLB_Bez varchar(60)
  ,@Param_ONLB_Name varchar(60)
  ,@Param_ONLB_Kenn varchar(10)
  ,@Param_ONLB_Vers varchar(3)
  ,@Param_ONLB_Date varchar(10)
  ,@Param_ONLB_Frei varchar(1)
  ,@Param_StampXml varchar(32)
  ,@Param_StampHtml varchar(32)
  ,@Param_BT10 varchar(30)
  ,@Param_BT11 varchar(30)
  ,@Param_BT12 varchar(30)
  ,@Param_BT13 varchar(30)
  ,@Param_BT14 varchar(30)
  ,@Param_BT17 varchar(30)
  ,@Param_BT18 varchar(30)
  ,@Param_BT71 varchar(30)
  ,@Param_BT19 varchar(50)
  ,@Param_OzFormel varchar(80)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)
  UPDATE [dbo].[ut_BelKopfExt] SET
    [PrjNr] = UPPER(RTRIM(@Param_PrjNr))
   ,[BelArt] = UPPER(RTRIM(@Param_BelArt))
   ,[BelNr] = UPPER(RTRIM(@Param_BelNr))
   ,[NkMengen] = dbo.itcfunc_integer(@Param_NkMengen)
   ,[Lose] = dbo.itcfunc_integer(@Param_Lose)
   ,[GaebOz] = RTRIM(@Param_GaebOz)
   ,[GaebDvNr] = RTRIM(@Param_GaebDvNr)
   ,[GaebBietNr] = RTRIM(@Param_GaebBietNr)
   ,[GaebVergNr] = RTRIM(@Param_GaebVergNr)
   ,[Untertitel] = dbo.itcfunc_integer(@Param_Untertitel)
   ,[ZuschFrist] = dbo.itcfunc_datetime(@Param_ZuschFrist)
   ,[SubZeit] = UPPER(RTRIM(@Param_SubZeit))
   ,[GaebLVBez] = RTRIM(@Param_GaebLVBez)
   ,[RwegSkonto] = dbo.itcfunc_integer(@Param_RwegSkonto)
   ,[LagerVerbu] = dbo.itcfunc_integer(@Param_LagerVerbu)
   ,[NewRwSusp] = dbo.itcfunc_integer(@Param_NewRwSusp)
   ,[CxLstgPos] = dbo.itcfunc_integer(@Param_CxLstgPos)
   ,[CxTextPos] = dbo.itcfunc_integer(@Param_CxTextPos)
   ,[CxVtNtPos] = dbo.itcfunc_integer(@Param_CxVtNtPos)
   ,[CxAufmass] = dbo.itcfunc_integer(@Param_CxAufmass)
   ,[bFormKeys] = dbo.itcfunc_integer(@Param_bFormKeys)
   ,[FormKeyFi] = RTRIM(@Param_FormKeyFi)
   ,[Floskeln] = dbo.itcfunc_integer(@Param_Floskeln)
   ,[GAEBArtMo] = dbo.itcfunc_integer(@Param_GAEBArtMo)
   ,[NrHwGC] = UPPER(RTRIM(@Param_NrHwGC))
   ,[SuSpOpts] = UPPER(RTRIM(@Param_SuSpOpts))
   ,[CuPreis] = dbo.itcfunc_float(@Param_CuPreis)
   ,[CalcEk2Vk] = dbo.itcfunc_integer(@Param_CalcEk2Vk)
   ,[CalcAuf2Vk] = dbo.itcfunc_integer(@Param_CalcAuf2Vk)
   ,[CalcNEP] = dbo.itcfunc_integer(@Param_CalcNEP)
   ,[ProgVers] = dbo.itcfunc_integer(@Param_ProgVers)
   ,[Sum_Netto] = dbo.itcfunc_float(@Param_Sum_Netto)
   ,[Sum_Gesamt] = dbo.itcfunc_float(@Param_Sum_Gesamt)
   ,[Sum_Mwst] = dbo.itcfunc_float(@Param_Sum_Mwst)
   ,[Sum_NettoB] = dbo.itcfunc_float(@Param_Sum_NettoB)
   ,[ZUAB_BRUTTO] = dbo.itcfunc_float(@Param_ZUAB_BRUTTO)
   ,[LVNETTO] = dbo.itcfunc_float(@Param_LVNETTO)
   ,[LVMWST] = dbo.itcfunc_float(@Param_LVMWST)
   ,[LVBRUTTO] = dbo.itcfunc_float(@Param_LVBRUTTO)
   ,[TRNet] = dbo.itcfunc_float(@Param_TRNet)
   ,[TRMws] = dbo.itcfunc_float(@Param_TRMws)
   ,[TRBru] = dbo.itcfunc_float(@Param_TRBru)
   ,[TRNet_BEZ] = dbo.itcfunc_float(@Param_TRNet_BEZ)
   ,[TRMws_BEZ] = dbo.itcfunc_float(@Param_TRMws_BEZ)
   ,[TRBru_BEZ] = dbo.itcfunc_float(@Param_TRBru_BEZ)
   ,[SkontoBasis] = dbo.itcfunc_float(@Param_SkontoBasis)
   ,[RWegRoot] = dbo.itcfunc_integer(@Param_RWegRoot)
   ,[RWegMwst] = dbo.itcfunc_integer(@Param_RWegMwst)
   ,[LastFormNr] = dbo.itcfunc_integer(@Param_LastFormNr)
   ,[DrkFlags1] = dbo.itcfunc_integer(@Param_DrkFlags1)
   ,[DrkFlags2] = dbo.itcfunc_integer(@Param_DrkFlags2)
   ,[AnzEPAnt] = dbo.itcfunc_integer(@Param_AnzEPAnt)
   ,[BezEPAnt1] = RTRIM(@Param_BezEPAnt1)
   ,[BezEPAnt2] = RTRIM(@Param_BezEPAnt2)
   ,[BezEPAnt3] = RTRIM(@Param_BezEPAnt3)
   ,[BezEPAnt4] = RTRIM(@Param_BezEPAnt4)
   ,[BezEPAnt5] = RTRIM(@Param_BezEPAnt5)
   ,[BezEPAnt6] = RTRIM(@Param_BezEPAnt6)
   ,[BezZeit] = RTRIM(@Param_BezZeit)
   ,[EpAnteile] = RTRIM(@Param_EpAnteile)
   ,[RndGPKfm] = dbo.itcfunc_integer(@Param_RndGPKfm)
   ,[NavJobNo] = UPPER(RTRIM(@Param_NavJobNo))
   ,[NavDocNo] = UPPER(RTRIM(@Param_NavDocNo))
   ,[NavDocNo2] = UPPER(RTRIM(@Param_NavDocNo2))
   ,[NavDocNo3] = UPPER(RTRIM(@Param_NavDocNo3))
   ,[AbwVK2LH] = dbo.itcfunc_float(@Param_AbwVK2LH)
   ,[AbwFaktor1] = dbo.itcfunc_float(@Param_AbwFaktor1)
   ,[NavDocType] = dbo.itcfunc_integer(@Param_NavDocType)
   ,[NoSelect] = dbo.itcfunc_integer(@Param_NoSelect)
   ,[Revision] = RTRIM(@Param_Revision)
   ,[Additional] = RTRIM(@Param_Additional)
   ,[RefNo1] = RTRIM(@Param_RefNo1)
   ,[RefNo2] = RTRIM(@Param_RefNo2)
   ,[RefNo3] = RTRIM(@Param_RefNo3)
   ,[RefNo4] = RTRIM(@Param_RefNo4)
   ,[RefDate1] = dbo.itcfunc_datetime(@Param_RefDate1)
   ,[RefDate2] = dbo.itcfunc_datetime(@Param_RefDate2)
   ,[RefDate3] = dbo.itcfunc_datetime(@Param_RefDate3)
   ,[RefDate4] = dbo.itcfunc_datetime(@Param_RefDate4)
   ,[RefText1] = RTRIM(@Param_RefText1)
   ,[RefText2] = RTRIM(@Param_RefText2)
   ,[RefText3] = RTRIM(@Param_RefText3)
   ,[RefText4] = RTRIM(@Param_RefText4)
   ,[DictPlane] = dbo.itcfunc_integer(@Param_DictPlane)
   ,[ONLB_Bez] = RTRIM(@Param_ONLB_Bez)
   ,[ONLB_Name] = RTRIM(@Param_ONLB_Name)
   ,[ONLB_Kenn] = UPPER(RTRIM(@Param_ONLB_Kenn))
   ,[ONLB_Vers] = dbo.itcfunc_integer(@Param_ONLB_Vers)
   ,[ONLB_Date] = dbo.itcfunc_datetime(@Param_ONLB_Date)
   ,[ONLB_Frei] = dbo.itcfunc_integer(@Param_ONLB_Frei)
   ,[StampXml] = UPPER(RTRIM(@Param_StampXml))
   ,[StampHtml] = UPPER(RTRIM(@Param_StampHtml))
   ,[BT10] = RTRIM(@Param_BT10)
   ,[BT11] = RTRIM(@Param_BT11)
   ,[BT12] = RTRIM(@Param_BT12)
   ,[BT13] = RTRIM(@Param_BT13)
   ,[BT14] = RTRIM(@Param_BT14)
   ,[BT17] = RTRIM(@Param_BT17)
   ,[BT18] = RTRIM(@Param_BT18)
   ,[BT71] = RTRIM(@Param_BT71)
   ,[BT19] = RTRIM(@Param_BT19)
   ,[OzFormel] = RTRIM(@Param_OzFormel)
  WHERE RecId = @mRI

  EXECUTE [dbo].[up_Sel2_BelKopfExt] @mRI
GO

-- delete
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Del_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Del_BelKopfExt] @mRI integer
AS
  DELETE FROM [dbo].[ut_BelKopfExt] WHERE RecId = @mRI
GO

-- text index
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_BelKopfExt')
  DROP PROCEDURE [dbo].[up_TrSel_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelKopfExt]
AS
  SELECT RecId,
    LTRIM(RTRIM([PrjNr]))
   +LTRIM(RTRIM([BelArt]))
   +LTRIM(RTRIM([BelNr]))
   +LTRIM(RTRIM([GaebOz]))
   +LTRIM(RTRIM([GaebDvNr]))
   +LTRIM(RTRIM([GaebBietNr]))
   +LTRIM(RTRIM([GaebVergNr]))
   +LTRIM(RTRIM([SubZeit]))
   +LTRIM(RTRIM([GaebLVBez]))
   +LTRIM(RTRIM([FormKeyFi]))
   +LTRIM(RTRIM([NrHwGC]))
   +LTRIM(RTRIM([SuSpOpts]))
   +LTRIM(RTRIM([BezEPAnt1]))
   +LTRIM(RTRIM([BezEPAnt2]))
   +LTRIM(RTRIM([BezEPAnt3]))
   +LTRIM(RTRIM([BezEPAnt4]))
   +LTRIM(RTRIM([BezEPAnt5]))
   +LTRIM(RTRIM([BezEPAnt6]))
   +LTRIM(RTRIM([BezZeit]))
   +LTRIM(RTRIM([EpAnteile]))
   +LTRIM(RTRIM([NavJobNo]))
   +LTRIM(RTRIM([NavDocNo]))
   +LTRIM(RTRIM([NavDocNo2]))
   +LTRIM(RTRIM([NavDocNo3]))
   +LTRIM(RTRIM([Revision]))
   +LTRIM(RTRIM([Additional]))
   +LTRIM(RTRIM([RefNo1]))
   +LTRIM(RTRIM([RefNo2]))
   +LTRIM(RTRIM([RefNo3]))
   +LTRIM(RTRIM([RefNo4]))
   +LTRIM(RTRIM([RefText1]))
   +LTRIM(RTRIM([RefText2]))
   +LTRIM(RTRIM([RefText3]))
   +LTRIM(RTRIM([RefText4]))
   +LTRIM(RTRIM([ONLB_Bez]))
   +LTRIM(RTRIM([ONLB_Name]))
   +LTRIM(RTRIM([ONLB_Kenn]))
   +LTRIM(RTRIM([StampXml]))
   +LTRIM(RTRIM([StampHtml]))
   +LTRIM(RTRIM([BT10]))
   +LTRIM(RTRIM([BT11]))
   +LTRIM(RTRIM([BT12]))
   +LTRIM(RTRIM([BT13]))
   +LTRIM(RTRIM([BT14]))
   +LTRIM(RTRIM([BT17]))
   +LTRIM(RTRIM([BT18]))
   +LTRIM(RTRIM([BT71]))
   +LTRIM(RTRIM([BT19]))
   +LTRIM(RTRIM([OzFormel]))
  AS Data FROM [dbo].[ut_BelKopfExt] WHERE RecId > 0 ORDER BY RecId
GO

-- reindex
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelKopfExt')
  DROP PROCEDURE [dbo].[up_Reorg_BelKopfExt]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelKopfExt] @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelKopfExt] 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_BelKopfExt] 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_BelKopfExt] )
  END
GO

-- logical key  ORDER BY PrjNr,BelArt,BelNr,RecId
IF 0 < (select count(*) from sysindexes si inner join sysobjects so on so.[xtype] = 'U' and so.[name] = 'ut_BelKopfExt' and so.[id] = si.[id] and si.[name] = 'Ik_Key0')
  DROP INDEX [Ik_Key0] ON [dbo].[ut_BelKopfExt]
GO
IF 0 = (select count(*) from sysindexes si inner join sysobjects so on so.[xtype] = 'U' and so.[name] = 'ut_BelKopfExt' and so.[id] = si.[id] and si.[name] = 'Ik_Key0')
  CREATE INDEX [Ik_Key0] ON [dbo].[ut_BelKopfExt] (PrjNr,BelArt,BelNr,RecId)
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_First_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_First_BelKopfExt_Key0] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) ORDER BY PrjNr,BelArt,BelNr,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_BelKopfExt_Key0] AS EXECUTE [dbo].[up_First_BelKopfExt_Key0]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_Last_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_Last_BelKopfExt_Key0] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_BelKopfExt_Key0] AS EXECUTE [dbo].[up_Last_BelKopfExt_Key0]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_Next_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_Next_BelKopfExt_Key0] @oldRecId integer AS
  DECLARE @oldPrjNr char(8)
  DECLARE @oldBelArt char(2)
  DECLARE @oldBelNr char(8)
  SELECT @oldPrjNr = PrjNr, @oldBelArt = BelArt, @oldBelNr = BelNr FROM [dbo].[ut_BelKopfExt] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr = @oldPrjNr) AND (BelArt = @oldBelArt) AND (BelNr > @oldBelNr)
    ORDER BY PrjNr,BelArt,BelNr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr = @oldPrjNr) AND (BelArt > @oldBelArt)
    ORDER BY PrjNr,BelArt,BelNr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr > @oldPrjNr)
    ORDER BY PrjNr,BelArt,BelNr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT 0 AS RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Next_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_Next_BelKopfExt_Key0] @oldRecId integer AS EXECUTE [dbo].[up_Next_BelKopfExt_Key0] @oldRecId')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_Prior_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_Prior_BelKopfExt_Key0] @oldRecId integer AS
  DECLARE @oldPrjNr char(8)
  DECLARE @oldBelArt char(2)
  DECLARE @oldBelNr char(8)
  SELECT @oldPrjNr = PrjNr, @oldBelArt = BelArt, @oldBelNr = BelNr FROM [dbo].[ut_BelKopfExt] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr = @oldPrjNr) AND (BelArt = @oldBelArt) AND (BelNr < @oldBelNr)
    ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr = @oldPrjNr) AND (BelArt < @oldBelArt)
    ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0)
    WHERE (PrjNr < @oldPrjNr)
    ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT 0 AS RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Prior_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_Prior_BelKopfExt_Key0] @oldRecId integer AS EXECUTE [dbo].[up_Prior_BelKopfExt_Key0] @oldRecId')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_Next50_BelKopfExt_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Next50_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[qp_Next50_BelKopfExt_Key0]
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_Prior50_BelKopfExt_Key0]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Prior50_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[qp_Prior50_BelKopfExt_Key0]
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_FindF_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_FindF_BelKopfExt_Key0] @xKey char(250), @xLen integer AS
  DECLARE @mPrjNr char(8) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,8)
  DECLARE @mBelArt char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,9,2)
  DECLARE @mBelNr char(8) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,11,8)

  -- pass 1 -- Abfrage mit vollständigen Feldern (absteigende Vergleichslänge)

  IF @xLen = 18 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt AND 
      BelNr = @mBelNr
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  IF @xLen = 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  IF @xLen = 8 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  -- pass 2 -- Abfrage mit teilweise unkompletten Felder (aufsteigende Vergleichslänge)

  IF @xLen < 8 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr >= @mPrjNr AND SUBSTRING(PrjNr,1,LEN(@mPrjNr)) = @mPrjNr
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  IF @xLen < 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt >= @mBelArt AND SUBSTRING(BelArt,1,LEN(@mBelArt)) = @mBelArt
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  IF @xLen < 18 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt AND 
      BelNr >= @mBelNr AND SUBSTRING(BelNr,1,LEN(@mBelNr)) = @mBelNr
      ORDER BY PrjNr,BelArt,BelNr,RecId
    RETURN
  END

  SELECT 0 AS RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_FindF_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_FindF_BelKopfExt_Key0] @xKey char(250), @xLen integer AS EXECUTE [dbo].[up_FindF_BelKopfExt_Key0] @xKey, @xLen')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelKopfExt_Key0')
  DROP PROCEDURE [dbo].[up_FindL_BelKopfExt_Key0]
GO
CREATE PROCEDURE [dbo].[up_FindL_BelKopfExt_Key0] @xKey char(250), @xLen integer AS
  DECLARE @mPrjNr char(8) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,8)
  DECLARE @mBelArt char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,9,2)
  DECLARE @mBelNr char(8) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,11,8)

  -- pass 1 -- Abfrage mit vollständigen Feldern (absteigende Vergleichslänge)

  IF @xLen = 18 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt AND 
      BelNr = @mBelNr
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  IF @xLen = 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  IF @xLen = 8 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  -- pass 2 -- Abfrage mit teilweise unkompletten Felder (aufsteigende Vergleichslänge)

  IF @xLen < 8 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      SUBSTRING(PrjNr,1,LEN(@mPrjNr)) = @mPrjNr
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  IF @xLen < 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      SUBSTRING(BelArt,1,LEN(@mBelArt)) = @mBelArt
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  IF @xLen < 18 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_BelKopfExt] WITH(INDEX = Ik_Key0) WHERE 
      PrjNr = @mPrjNr AND 
      BelArt = @mBelArt AND 
      SUBSTRING(BelNr,1,LEN(@mBelNr)) = @mBelNr
      ORDER BY PrjNr desc,BelArt desc,BelNr desc,RecId desc
    RETURN
  END

  SELECT 0 AS RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_FindL_BelKopfExt_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_FindL_BelKopfExt_Key0] @xKey char(250), @xLen integer AS EXECUTE [dbo].[up_FindL_BelKopfExt_Key0] @xKey, @xLen')
GO


