------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_BelPos')
BEGIN
CREATE TABLE [dbo].[ut_BelPos]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[PrjNr] char(8) DEFAULT ' '
  ,[BelArt] char(2) DEFAULT ' '
  ,[BelNr] char(8) DEFAULT ' '
  ,[LfdNr] char(6) DEFAULT ' '
  ,[Ebene] integer DEFAULT 0
  ,[RefKey] char(6) DEFAULT ' '
  ,[SatzArt] integer DEFAULT 0
  ,[Nachtrag] integer DEFAULT 0
  ,[Bedarf] tinyint DEFAULT 0
  ,[Alternativ] tinyint DEFAULT 0
  ,[Entfaellt] tinyint DEFAULT 0
  ,[Fixed] tinyint DEFAULT 0
  ,[Marked] tinyint DEFAULT 0
  ,[Fremd] tinyint DEFAULT 0
  ,[Vk2JN] tinyint DEFAULT 0
  ,[LohnJN] tinyint DEFAULT 0
  ,[MatJN] tinyint DEFAULT 0
  ,[PosNr] char(20) DEFAULT ' '
  ,[ArtNr] char(20) DEFAULT ' '
  ,[Ktxt1] char(50) DEFAULT ' '
  ,[Menge] float DEFAULT 0
  ,[VkMat] float DEFAULT 0
  ,[VkLohn] float DEFAULT 0
  ,[VkFremd] float DEFAULT 0
  ,[EkMat] float DEFAULT 0
  ,[EkLohn] float DEFAULT 0
  ,[EkFremd] float DEFAULT 0
  ,[RWegZube] integer DEFAULT 0
  ,[RWegNe] integer DEFAULT 0
  ,[NeFlag] tinyint DEFAULT 0
  ,[EkZube] float DEFAULT 0
  ,[MittelLohn] float DEFAULT 0
  ,[RabattDM] float DEFAULT 0
  ,[RabattVH] float DEFAULT 0
  ,[Zeit] float DEFAULT 0
  ,[Aufwand] float DEFAULT 0
  ,[Me] char(6) DEFAULT ' '
  ,[Pe] char(2) DEFAULT ' '
  ,[Gebinde] float DEFAULT 0
  ,[AufLohn] float DEFAULT 0
  ,[AufMat] float DEFAULT 0
  ,[Ktxt2] char(50) DEFAULT ' '
  ,[Ktxt3] char(50) DEFAULT ' '
  ,[KzDrk1] integer DEFAULT 0
  ,[KzDrk2] integer DEFAULT 0
  ,[TxtNr] char(20) DEFAULT ' '
  ,[DrkIndi] tinyint DEFAULT 0
  ,[DrkMenge] tinyint DEFAULT 0
  ,[DrkEP] tinyint DEFAULT 0
  ,[DrkGP] tinyint DEFAULT 0
  ,[DrkLM] tinyint DEFAULT 0
  ,[DrkUpos] tinyint DEFAULT 0
  ,[DrkUposPr] tinyint DEFAULT 0
  ,[DrkUposAbs] tinyint DEFAULT 0
  ,[Vk2Lohn] float DEFAULT 0
  ,[Vk2Mat] float DEFAULT 0
  ,[Brutto] float DEFAULT 0
  ,[Rab1] float DEFAULT 0
  ,[Rab2] float DEFAULT 0
  ,[EkNe] float DEFAULT 0
  ,[OldMLohn] tinyint DEFAULT 0
  ,[Faktor1] float DEFAULT 0
  ,[Faktor2] float DEFAULT 0
  ,[Faktor3] float DEFAULT 0
  ,[ZSAbStart] tinyint DEFAULT 0
  ,[ZSNeutral] tinyint DEFAULT 0
  ,[ZSWieVor] tinyint DEFAULT 0
  ,[DrkFett] tinyint DEFAULT 0
  ,[DrkFF] tinyint DEFAULT 0
  ,[DrkLF] tinyint DEFAULT 0
  ,[KzMwst] integer DEFAULT 0
  ,[MengeVA] float DEFAULT 0
  ,[Kst] char(20) DEFAULT ' '
  ,[Ktr] char(20) DEFAULT ' '
  ,[EGruMat] char(3) DEFAULT ' '
  ,[EGruLohn] char(3) DEFAULT ' '
  ,[SuSp] char(20) DEFAULT ' '
  ,[SuSpTyp] integer DEFAULT 0
  ,[AbsMenge] float DEFAULT 0
  ,[EPMat] float DEFAULT 0
  ,[EPLohn] float DEFAULT 0
  ,[EPPos] float DEFAULT 0
  ,[GPPos] float DEFAULT 0
  ,[AbsGP] float DEFAULT 0
  ,[ParentRef] char(6) DEFAULT ' '
  ,[Expanded] tinyint DEFAULT 0
  ,[Visible] tinyint DEFAULT 0
  ,[SuSpValid] tinyint DEFAULT 0
  ,[Dropped] tinyint DEFAULT 0
  ,[Saved] tinyint DEFAULT 0
  ,[EkSonstig] float DEFAULT 0
  ,[VkBedarf] float DEFAULT 0
  ,[CuGewicht] float DEFAULT 0
  ,[KGruppe] integer DEFAULT 0
  ,[FloskelJN] tinyint DEFAULT 0
  ,[GAEBxOZ] char(20) DEFAULT ' '
  ,[GAEBxTyp] integer DEFAULT 0
  ,[GAEBxFrM] tinyint DEFAULT 0
  ,[AlGewicht] float DEFAULT 0
  ,[SumBrutto] float DEFAULT 0
  ,[ZZGrpNr] integer DEFAULT 0
  ,[ZZLfdNr] integer DEFAULT 0
  ,[EPAufgl] tinyint DEFAULT 0
  ,[EpAnteile] char(18) DEFAULT ' '
  ,[VkAnt1] float DEFAULT 0
  ,[VkAnt2] float DEFAULT 0
  ,[VkAnt3] float DEFAULT 0
  ,[VkAnt4] float DEFAULT 0
  ,[Herkunft] integer DEFAULT 0
  ,[BuchGrp] char(10) DEFAULT ' '
  ,[BezugAuf] char(6) DEFAULT ' '
  ,[BezugBis] char(6) DEFAULT ' '
  ,[Flags] integer DEFAULT 0
  ,[VkAnt5] float DEFAULT 0
  ,[VkAnt6] float DEFAULT 0
  ,[CVkAnt1] float DEFAULT 0
  ,[CVkAnt2] float DEFAULT 0
  ,[CVkAnt3] float DEFAULT 0
  ,[CVkAnt4] float DEFAULT 0
  ,[CVkAnt5] float DEFAULT 0
  ,[CVkAnt6] float DEFAULT 0
  ,[EkAnteile] char(168) DEFAULT ' '
  CONSTRAINT [Pk_BelPos]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelPos_KeyDel')
  DROP TRIGGER [dbo].[tr_BelPos_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_BelPos_KeyUpd')
  DROP TRIGGER [dbo].[tr_BelPos_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_BelPos_Keys')
  DROP TABLE [dbo].[ut_BelPos_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] 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_BelPos' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] 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_BelPos' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] 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_BelPos' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [LfdNr] char(6) 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_BelPos' and sc.[name] = 'Ebene')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Ebene] 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_BelPos' and sc.[name] = 'RefKey')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [RefKey] char(6) 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_BelPos' and sc.[name] = 'SatzArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [SatzArt] 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_BelPos' and sc.[name] = 'Nachtrag')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Nachtrag] 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_BelPos' and sc.[name] = 'Bedarf')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Bedarf] 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_BelPos' and sc.[name] = 'Alternativ')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Alternativ] 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_BelPos' and sc.[name] = 'Entfaellt')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Entfaellt] 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_BelPos' and sc.[name] = 'Fixed')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Fixed] 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_BelPos' and sc.[name] = 'Marked')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Marked] 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_BelPos' and sc.[name] = 'Fremd')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Fremd] 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_BelPos' and sc.[name] = 'Vk2JN')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Vk2JN] 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_BelPos' and sc.[name] = 'LohnJN')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [LohnJN] 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_BelPos' and sc.[name] = 'MatJN')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [MatJN] 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_BelPos' and sc.[name] = 'PosNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [PosNr] 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_BelPos' and sc.[name] = 'ArtNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ArtNr] 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_BelPos' and sc.[name] = 'Ktxt1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Ktxt1] char(50) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Menge')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Menge] 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_BelPos' and sc.[name] = 'VkMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkMat] 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_BelPos' and sc.[name] = 'VkLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkLohn] 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_BelPos' and sc.[name] = 'VkFremd')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkFremd] 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_BelPos' and sc.[name] = 'EkMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkMat] 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_BelPos' and sc.[name] = 'EkLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkLohn] 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_BelPos' and sc.[name] = 'EkFremd')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkFremd] 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_BelPos' and sc.[name] = 'RWegZube')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [RWegZube] 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_BelPos' and sc.[name] = 'RWegNe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [RWegNe] 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_BelPos' and sc.[name] = 'NeFlag')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [NeFlag] 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_BelPos' and sc.[name] = 'EkZube')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkZube] 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_BelPos' and sc.[name] = 'MittelLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [MittelLohn] 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_BelPos' and sc.[name] = 'RabattDM')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [RabattDM] 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_BelPos' and sc.[name] = 'RabattVH')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [RabattVH] 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_BelPos' and sc.[name] = 'Zeit')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Zeit] 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_BelPos' and sc.[name] = 'Aufwand')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Aufwand] 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_BelPos' and sc.[name] = 'Me')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Me] char(6) 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_BelPos' and sc.[name] = 'Pe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Pe] 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_BelPos' and sc.[name] = 'Gebinde')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Gebinde] 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_BelPos' and sc.[name] = 'AufLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [AufLohn] 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_BelPos' and sc.[name] = 'AufMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [AufMat] 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_BelPos' and sc.[name] = 'Ktxt2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Ktxt2] char(50) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Ktxt3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Ktxt3] char(50) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'KzDrk1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [KzDrk1] 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_BelPos' and sc.[name] = 'KzDrk2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [KzDrk2] 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_BelPos' and sc.[name] = 'TxtNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [TxtNr] 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_BelPos' and sc.[name] = 'DrkIndi')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkIndi] 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_BelPos' and sc.[name] = 'DrkMenge')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkMenge] 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_BelPos' and sc.[name] = 'DrkEP')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkEP] 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_BelPos' and sc.[name] = 'DrkGP')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkGP] 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_BelPos' and sc.[name] = 'DrkLM')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkLM] 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_BelPos' and sc.[name] = 'DrkUpos')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkUpos] 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_BelPos' and sc.[name] = 'DrkUposPr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkUposPr] 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_BelPos' and sc.[name] = 'DrkUposAbs')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkUposAbs] 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_BelPos' and sc.[name] = 'Vk2Lohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Vk2Lohn] 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_BelPos' and sc.[name] = 'Vk2Mat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Vk2Mat] 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_BelPos' and sc.[name] = 'Brutto')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [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_BelPos' and sc.[name] = 'Rab1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Rab1] 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_BelPos' and sc.[name] = 'Rab2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Rab2] 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_BelPos' and sc.[name] = 'EkNe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkNe] 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_BelPos' and sc.[name] = 'OldMLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [OldMLohn] 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_BelPos' and sc.[name] = 'Faktor1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Faktor1] 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_BelPos' and sc.[name] = 'Faktor2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Faktor2] 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_BelPos' and sc.[name] = 'Faktor3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Faktor3] 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_BelPos' and sc.[name] = 'ZSAbStart')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ZSAbStart] 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_BelPos' and sc.[name] = 'ZSNeutral')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ZSNeutral] 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_BelPos' and sc.[name] = 'ZSWieVor')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ZSWieVor] 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_BelPos' and sc.[name] = 'DrkFett')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkFett] 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_BelPos' and sc.[name] = 'DrkFF')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkFF] 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_BelPos' and sc.[name] = 'DrkLF')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [DrkLF] 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_BelPos' and sc.[name] = 'KzMwst')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [KzMwst] 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_BelPos' and sc.[name] = 'MengeVA')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [MengeVA] 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_BelPos' and sc.[name] = 'Kst')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Kst] 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_BelPos' and sc.[name] = 'Ktr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Ktr] 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_BelPos' and sc.[name] = 'EGruMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EGruMat] char(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_BelPos' and sc.[name] = 'EGruLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EGruLohn] char(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_BelPos' and sc.[name] = 'SuSp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [SuSp] 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_BelPos' and sc.[name] = 'SuSpTyp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [SuSpTyp] 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_BelPos' and sc.[name] = 'AbsMenge')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [AbsMenge] 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_BelPos' and sc.[name] = 'EPMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EPMat] 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_BelPos' and sc.[name] = 'EPLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EPLohn] 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_BelPos' and sc.[name] = 'EPPos')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EPPos] 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_BelPos' and sc.[name] = 'GPPos')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [GPPos] 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_BelPos' and sc.[name] = 'AbsGP')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [AbsGP] 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_BelPos' and sc.[name] = 'ParentRef')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ParentRef] char(6) 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_BelPos' and sc.[name] = 'Expanded')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Expanded] 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_BelPos' and sc.[name] = 'Visible')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Visible] 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_BelPos' and sc.[name] = 'SuSpValid')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [SuSpValid] 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_BelPos' and sc.[name] = 'Dropped')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Dropped] 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_BelPos' and sc.[name] = 'Saved')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Saved] 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_BelPos' and sc.[name] = 'EkSonstig')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkSonstig] 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_BelPos' and sc.[name] = 'VkBedarf')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkBedarf] 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_BelPos' and sc.[name] = 'CuGewicht')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CuGewicht] 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_BelPos' and sc.[name] = 'KGruppe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [KGruppe] 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_BelPos' and sc.[name] = 'FloskelJN')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [FloskelJN] 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_BelPos' and sc.[name] = 'GAEBxOZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [GAEBxOZ] 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_BelPos' and sc.[name] = 'GAEBxTyp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [GAEBxTyp] 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_BelPos' and sc.[name] = 'GAEBxFrM')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [GAEBxFrM] 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_BelPos' and sc.[name] = 'AlGewicht')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [AlGewicht] 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_BelPos' and sc.[name] = 'SumBrutto')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [SumBrutto] 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_BelPos' and sc.[name] = 'ZZGrpNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ZZGrpNr] 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_BelPos' and sc.[name] = 'ZZLfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [ZZLfdNr] 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_BelPos' and sc.[name] = 'EPAufgl')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EPAufgl] 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_BelPos' and sc.[name] = 'EpAnteile')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EpAnteile] char(18) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'VkAnt1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt1] 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_BelPos' and sc.[name] = 'VkAnt2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt2] 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_BelPos' and sc.[name] = 'VkAnt3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt3] 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_BelPos' and sc.[name] = 'VkAnt4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt4] 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_BelPos' and sc.[name] = 'Herkunft')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Herkunft] 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_BelPos' and sc.[name] = 'BuchGrp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [BuchGrp] 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_BelPos' and sc.[name] = 'BezugAuf')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [BezugAuf] char(6) 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_BelPos' and sc.[name] = 'BezugBis')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [BezugBis] char(6) 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_BelPos' and sc.[name] = 'Flags')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [Flags] 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_BelPos' and sc.[name] = 'VkAnt5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt5] 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_BelPos' and sc.[name] = 'VkAnt6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [VkAnt6] 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_BelPos' and sc.[name] = 'CVkAnt1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt1] 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_BelPos' and sc.[name] = 'CVkAnt2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt2] 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_BelPos' and sc.[name] = 'CVkAnt3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt3] 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_BelPos' and sc.[name] = 'CVkAnt4')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt4] 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_BelPos' and sc.[name] = 'CVkAnt5')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt5] 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_BelPos' and sc.[name] = 'CVkAnt6')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [CVkAnt6] 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_BelPos' and sc.[name] = 'EkAnteile')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ADD [EkAnteile] char(168) NOT NULL DEFAULT ' '
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'PrjNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [PrjNr] char(8)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'BelArt')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [BelArt] char(2)
END
GO
IF 8 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'BelNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [BelNr] char(8)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'LfdNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [LfdNr] char(6)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'RefKey')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [RefKey] char(6)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'PosNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [PosNr] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'ArtNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [ArtNr] char(20)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Ktxt1')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Ktxt1] char(50)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Me')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Me] char(6)
END
GO
IF 2 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Pe')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Pe] char(2)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Ktxt2')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Ktxt2] char(50)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Ktxt3')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Ktxt3] char(50)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'TxtNr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [TxtNr] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Kst')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Kst] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'Ktr')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [Ktr] char(20)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'EGruMat')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [EGruMat] char(3)
END
GO
IF 3 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'EGruLohn')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [EGruLohn] char(3)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'SuSp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [SuSp] char(20)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'ParentRef')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [ParentRef] char(6)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'GAEBxOZ')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [GAEBxOZ] char(20)
END
GO
IF 18 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'EpAnteile')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [EpAnteile] char(18)
END
GO
IF 10 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'BuchGrp')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [BuchGrp] char(10)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'BezugAuf')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [BezugAuf] char(6)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'BezugBis')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [BezugBis] char(6)
END
GO
IF 168 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_BelPos' and sc.[name] = 'EkAnteile')
BEGIN
  ALTER TABLE [dbo].[ut_BelPos] ALTER COLUMN [EkAnteile] char(168)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'BelPos')
  DROP VIEW [dbo].[BelPos]
GO
CREATE VIEW [dbo].[BelPos] AS
  SELECT * FROM [dbo].[ut_BelPos]
GO
CREATE TABLE [dbo].[ut_BelPos_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Filter] TINYINT NOT NULL
  ,[Key00_Value] CHAR(34) NOT NULL
  ,[Key01_Filter] TINYINT NOT NULL
  ,[Key01_Value] CHAR(48) NOT NULL
  ,[Key02_Filter] TINYINT NOT NULL
  ,[Key02_Value] CHAR(48) NOT NULL
  ,[Key03_Value] CHAR(34) NOT NULL
  ,[Key04_Filter] TINYINT NOT NULL
  ,[Key04_Value] CHAR(34) NOT NULL
  ,[Key05_Filter] TINYINT NOT NULL
  ,[Key05_Value] CHAR(40) NOT NULL
  ,[Key06_Filter] TINYINT NOT NULL
  ,[Key06_Value] CHAR(28) NOT NULL
  ,[Key07_Filter] TINYINT NOT NULL
  ,[Key07_Value] CHAR(48) NOT NULL
  ,[Key08_Value] CHAR(24) NOT NULL
  ,[Key09_Filter] TINYINT NOT NULL
  ,[Key09_Value] CHAR(44) NOT NULL
  ,[Key10_Filter] TINYINT NOT NULL
  ,[Key10_Value] CHAR(36) NOT NULL
  ,[Key11_Filter] TINYINT NOT NULL
  ,[Key11_Value] CHAR(38) NOT NULL
  ,[Key12_Filter] TINYINT NOT NULL
  ,[Key12_Value] CHAR(54) NOT NULL
  ,[Key13_Filter] TINYINT NOT NULL
  ,[Key13_Value] CHAR(52) NOT NULL
  CONSTRAINT [Pk_ut_BelPos_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_BelPos_KeyDel] ON [dbo].[ut_BelPos]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_BelPos_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_BelPos_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Filter],[Key00_Value],[Key01_Filter],[Key01_Value],[Key02_Filter],[Key02_Value],[Key03_Value],[Key04_Filter],[Key04_Value],[Key05_Filter],[Key05_Value],[Key06_Filter],[Key06_Value],[Key07_Filter],[Key07_Value],[Key08_Value],[Key09_Filter],[Key09_Value],[Key10_Filter],[Key10_Value],[Key11_Filter],[Key11_Value],[Key12_Filter],[Key12_Value],[Key13_Filter],[Key13_Value])
    (SELECT [RecId],[MandId]
     ,CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR(RecId,10))
     ,CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[PosNr])+STR(RecId,10))
     ,CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR(RecId,10))
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[RefKey])+STR(RecId,10))
     ,CASE WHEN (0 =  Dropped) AND (1 =  Visible) THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR(RecId,10))
     ,CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[ParentRef])+convert(char(6),[LfdNr])+STR(RecId,10))
     ,CASE WHEN 0 =  Saved THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR(RecId,10))
     ,CASE WHEN (0 =  Dropped) AND (SatzArt = 17) THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR(RecId,10))
     ,UPPER(convert(char(8),[PrjNr])+convert(char(6),[RefKey])+STR(RecId,10))
     ,CASE WHEN (BelArt >= ' 1') AND (BelArt <= ' 4') AND ((SatzArt = 7) OR (SatzArt = 8)) THEN 1 ELSE 0 END
     ,UPPER(convert(char(20),[ArtNr])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR(RecId,10))
     ,CASE WHEN (0 =  Dropped) AND (SatzArt = 7) THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR([KGruppe],2,0)+convert(char(6),[ParentRef])+STR(RecId,10))
     ,CASE WHEN (0 =  Dropped) AND ((SatzArt = 7) OR (SatzArt = 8)) AND (BelArt >= ' 1') AND (BelArt <= ' 4') THEN 1 ELSE 0 END
     ,UPPER(convert(char(20),[ArtNr])+convert(char(8),[BelNr])+STR(RecId,10))
     ,CASE WHEN (0 =  Dropped) AND ((SatzArt = 7) OR (SatzArt = 8)) THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+convert(char(6),[LfdNr])+STR(RecId,10))
     ,CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
     ,UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR([ZZGrpNr],3,0)+STR([ZZLfdNr],1,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_BelPos_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR([RecId],10))
   ,[Key00_Filter] = CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
   ,[Key01_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[PosNr])+STR([RecId],10))
   ,[Key01_Filter] = CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
   ,[Key02_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR([RecId],10))
   ,[Key02_Filter] = CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
   ,[Key03_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[RefKey])+STR([RecId],10))
   ,[Key04_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR([RecId],10))
   ,[Key04_Filter] = CASE WHEN (0 =  Dropped) AND (1 =  Visible) THEN 1 ELSE 0 END
   ,[Key05_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(6),[ParentRef])+convert(char(6),[LfdNr])+STR([RecId],10))
   ,[Key05_Filter] = CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
   ,[Key06_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR([RecId],10))
   ,[Key06_Filter] = CASE WHEN 0 =  Saved THEN 1 ELSE 0 END
   ,[Key07_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR([RecId],10))
   ,[Key07_Filter] = CASE WHEN (0 =  Dropped) AND (SatzArt = 17) THEN 1 ELSE 0 END
   ,[Key08_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(6),[RefKey])+STR([RecId],10))
   ,[Key09_Value] = UPPER(convert(char(20),[ArtNr])+convert(char(8),[BelNr])+convert(char(6),[LfdNr])+STR([RecId],10))
   ,[Key09_Filter] = CASE WHEN (BelArt >= ' 1') AND (BelArt <= ' 4') AND ((SatzArt = 7) OR (SatzArt = 8)) THEN 1 ELSE 0 END
   ,[Key10_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+STR([KGruppe],2,0)+convert(char(6),[ParentRef])+STR([RecId],10))
   ,[Key10_Filter] = CASE WHEN (0 =  Dropped) AND (SatzArt = 7) THEN 1 ELSE 0 END
   ,[Key11_Value] = UPPER(convert(char(20),[ArtNr])+convert(char(8),[BelNr])+STR([RecId],10))
   ,[Key11_Filter] = CASE WHEN (0 =  Dropped) AND ((SatzArt = 7) OR (SatzArt = 8)) AND (BelArt >= ' 1') AND (BelArt <= ' 4') THEN 1 ELSE 0 END
   ,[Key12_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+convert(char(6),[LfdNr])+STR([RecId],10))
   ,[Key12_Filter] = CASE WHEN (0 =  Dropped) AND ((SatzArt = 7) OR (SatzArt = 8)) THEN 1 ELSE 0 END
   ,[Key13_Value] = UPPER(convert(char(8),[PrjNr])+convert(char(2),[BelArt])+convert(char(8),[BelNr])+convert(char(20),[ArtNr])+STR([ZZGrpNr],3,0)+STR([ZZLfdNr],1,0)+STR([RecId],10))
   ,[Key13_Filter] = CASE WHEN 0 =  Dropped THEN 1 ELSE 0 END
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_BelPos')
  DROP PROCEDURE [dbo].[up_Add_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Add_BelPos] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_BelPos])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelPos] (RecId) VALUES( @NeueId )
  IF @@ERROR = 0
  BEGIN
    SELECT @NeueId AS RecId
    RETURN
  END
  SELECT 0 AS RecId
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_BelPos')
  DROP PROCEDURE [dbo].[up_Upd_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Upd_BelPos]
  @RI integer
 ,@Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_LfdNr char(6)
 ,@Parm_Ebene integer
 ,@Parm_RefKey char(6)
 ,@Parm_SatzArt integer
 ,@Parm_Nachtrag integer
 ,@Parm_Bedarf tinyint
 ,@Parm_Alternativ tinyint
 ,@Parm_Entfaellt tinyint
 ,@Parm_Fixed tinyint
 ,@Parm_Marked tinyint
 ,@Parm_Fremd tinyint
 ,@Parm_Vk2JN tinyint
 ,@Parm_LohnJN tinyint
 ,@Parm_MatJN tinyint
 ,@Parm_PosNr char(20)
 ,@Parm_ArtNr char(20)
 ,@Parm_Ktxt1 char(50)
 ,@Parm_Menge float
 ,@Parm_VkMat float
 ,@Parm_VkLohn float
 ,@Parm_VkFremd float
 ,@Parm_EkMat float
 ,@Parm_EkLohn float
 ,@Parm_EkFremd float
 ,@Parm_RWegZube integer
 ,@Parm_RWegNe integer
 ,@Parm_NeFlag tinyint
 ,@Parm_EkZube float
 ,@Parm_MittelLohn float
 ,@Parm_RabattDM float
 ,@Parm_RabattVH float
 ,@Parm_Zeit float
 ,@Parm_Aufwand float
 ,@Parm_Me char(6)
 ,@Parm_Pe char(2)
 ,@Parm_Gebinde float
 ,@Parm_AufLohn float
 ,@Parm_AufMat float
 ,@Parm_Ktxt2 char(50)
 ,@Parm_Ktxt3 char(50)
 ,@Parm_KzDrk1 integer
 ,@Parm_KzDrk2 integer
 ,@Parm_TxtNr char(20)
 ,@Parm_DrkIndi tinyint
 ,@Parm_DrkMenge tinyint
 ,@Parm_DrkEP tinyint
 ,@Parm_DrkGP tinyint
 ,@Parm_DrkLM tinyint
 ,@Parm_DrkUpos tinyint
 ,@Parm_DrkUposPr tinyint
 ,@Parm_DrkUposAbs tinyint
 ,@Parm_Vk2Lohn float
 ,@Parm_Vk2Mat float
 ,@Parm_Brutto float
 ,@Parm_Rab1 float
 ,@Parm_Rab2 float
 ,@Parm_EkNe float
 ,@Parm_OldMLohn tinyint
 ,@Parm_Faktor1 float
 ,@Parm_Faktor2 float
 ,@Parm_Faktor3 float
 ,@Parm_ZSAbStart tinyint
 ,@Parm_ZSNeutral tinyint
 ,@Parm_ZSWieVor tinyint
 ,@Parm_DrkFett tinyint
 ,@Parm_DrkFF tinyint
 ,@Parm_DrkLF tinyint
 ,@Parm_KzMwst integer
 ,@Parm_MengeVA float
 ,@Parm_Kst char(20)
 ,@Parm_Ktr char(20)
 ,@Parm_EGruMat char(3)
 ,@Parm_EGruLohn char(3)
 ,@Parm_SuSp char(20)
 ,@Parm_SuSpTyp integer
 ,@Parm_AbsMenge float
 ,@Parm_EPMat float
 ,@Parm_EPLohn float
 ,@Parm_EPPos float
 ,@Parm_GPPos float
 ,@Parm_AbsGP float
 ,@Parm_ParentRef char(6)
 ,@Parm_Expanded tinyint
 ,@Parm_Visible tinyint
 ,@Parm_SuSpValid tinyint
 ,@Parm_Dropped tinyint
 ,@Parm_Saved tinyint
 ,@Parm_EkSonstig float
 ,@Parm_VkBedarf float
 ,@Parm_CuGewicht float
 ,@Parm_KGruppe integer
 ,@Parm_FloskelJN tinyint
 ,@Parm_GAEBxOZ char(20)
 ,@Parm_GAEBxTyp integer
 ,@Parm_GAEBxFrM tinyint
 ,@Parm_AlGewicht float
 ,@Parm_SumBrutto float
 ,@Parm_ZZGrpNr integer
 ,@Parm_ZZLfdNr integer
 ,@Parm_EPAufgl tinyint
 ,@Parm_EpAnteile char(18)
 ,@Parm_VkAnt1 float
 ,@Parm_VkAnt2 float
 ,@Parm_VkAnt3 float
 ,@Parm_VkAnt4 float
 ,@Parm_Herkunft integer
 ,@Parm_BuchGrp char(10)
 ,@Parm_BezugAuf char(6)
 ,@Parm_BezugBis char(6)
 ,@Parm_Flags integer
 ,@Parm_VkAnt5 float
 ,@Parm_VkAnt6 float
 ,@Parm_CVkAnt1 float
 ,@Parm_CVkAnt2 float
 ,@Parm_CVkAnt3 float
 ,@Parm_CVkAnt4 float
 ,@Parm_CVkAnt5 float
 ,@Parm_CVkAnt6 float
 ,@Parm_EkAnteile char(168)
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_BelPos] SET
     [PrjNr] = RTRIM(@Parm_PrjNr)
    ,[BelArt] = RTRIM(@Parm_BelArt)
    ,[BelNr] = RTRIM(@Parm_BelNr)
    ,[LfdNr] = RTRIM(@Parm_LfdNr)
    ,[Ebene] = @Parm_Ebene
    ,[RefKey] = RTRIM(@Parm_RefKey)
    ,[SatzArt] = @Parm_SatzArt
    ,[Nachtrag] = @Parm_Nachtrag
    ,[Bedarf] = @Parm_Bedarf
    ,[Alternativ] = @Parm_Alternativ
    ,[Entfaellt] = @Parm_Entfaellt
    ,[Fixed] = @Parm_Fixed
    ,[Marked] = @Parm_Marked
    ,[Fremd] = @Parm_Fremd
    ,[Vk2JN] = @Parm_Vk2JN
    ,[LohnJN] = @Parm_LohnJN
    ,[MatJN] = @Parm_MatJN
    ,[PosNr] = RTRIM(@Parm_PosNr)
    ,[ArtNr] = RTRIM(@Parm_ArtNr)
    ,[Ktxt1] = RTRIM(@Parm_Ktxt1)
    ,[Menge] = @Parm_Menge
    ,[VkMat] = @Parm_VkMat
    ,[VkLohn] = @Parm_VkLohn
    ,[VkFremd] = @Parm_VkFremd
    ,[EkMat] = @Parm_EkMat
    ,[EkLohn] = @Parm_EkLohn
    ,[EkFremd] = @Parm_EkFremd
    ,[RWegZube] = @Parm_RWegZube
    ,[RWegNe] = @Parm_RWegNe
    ,[NeFlag] = @Parm_NeFlag
    ,[EkZube] = @Parm_EkZube
    ,[MittelLohn] = @Parm_MittelLohn
    ,[RabattDM] = @Parm_RabattDM
    ,[RabattVH] = @Parm_RabattVH
    ,[Zeit] = @Parm_Zeit
    ,[Aufwand] = @Parm_Aufwand
    ,[Me] = RTRIM(@Parm_Me)
    ,[Pe] = RTRIM(@Parm_Pe)
    ,[Gebinde] = @Parm_Gebinde
    ,[AufLohn] = @Parm_AufLohn
    ,[AufMat] = @Parm_AufMat
    ,[Ktxt2] = RTRIM(@Parm_Ktxt2)
    ,[Ktxt3] = RTRIM(@Parm_Ktxt3)
    ,[KzDrk1] = @Parm_KzDrk1
    ,[KzDrk2] = @Parm_KzDrk2
    ,[TxtNr] = RTRIM(@Parm_TxtNr)
    ,[DrkIndi] = @Parm_DrkIndi
    ,[DrkMenge] = @Parm_DrkMenge
    ,[DrkEP] = @Parm_DrkEP
    ,[DrkGP] = @Parm_DrkGP
    ,[DrkLM] = @Parm_DrkLM
    ,[DrkUpos] = @Parm_DrkUpos
    ,[DrkUposPr] = @Parm_DrkUposPr
    ,[DrkUposAbs] = @Parm_DrkUposAbs
    ,[Vk2Lohn] = @Parm_Vk2Lohn
    ,[Vk2Mat] = @Parm_Vk2Mat
    ,[Brutto] = @Parm_Brutto
    ,[Rab1] = @Parm_Rab1
    ,[Rab2] = @Parm_Rab2
    ,[EkNe] = @Parm_EkNe
    ,[OldMLohn] = @Parm_OldMLohn
    ,[Faktor1] = @Parm_Faktor1
    ,[Faktor2] = @Parm_Faktor2
    ,[Faktor3] = @Parm_Faktor3
    ,[ZSAbStart] = @Parm_ZSAbStart
    ,[ZSNeutral] = @Parm_ZSNeutral
    ,[ZSWieVor] = @Parm_ZSWieVor
    ,[DrkFett] = @Parm_DrkFett
    ,[DrkFF] = @Parm_DrkFF
    ,[DrkLF] = @Parm_DrkLF
    ,[KzMwst] = @Parm_KzMwst
    ,[MengeVA] = @Parm_MengeVA
    ,[Kst] = RTRIM(@Parm_Kst)
    ,[Ktr] = RTRIM(@Parm_Ktr)
    ,[EGruMat] = RTRIM(@Parm_EGruMat)
    ,[EGruLohn] = RTRIM(@Parm_EGruLohn)
    ,[SuSp] = RTRIM(@Parm_SuSp)
    ,[SuSpTyp] = @Parm_SuSpTyp
    ,[AbsMenge] = @Parm_AbsMenge
    ,[EPMat] = @Parm_EPMat
    ,[EPLohn] = @Parm_EPLohn
    ,[EPPos] = @Parm_EPPos
    ,[GPPos] = @Parm_GPPos
    ,[AbsGP] = @Parm_AbsGP
    ,[ParentRef] = RTRIM(@Parm_ParentRef)
    ,[Expanded] = @Parm_Expanded
    ,[Visible] = @Parm_Visible
    ,[SuSpValid] = @Parm_SuSpValid
    ,[Dropped] = @Parm_Dropped
    ,[Saved] = @Parm_Saved
    ,[EkSonstig] = @Parm_EkSonstig
    ,[VkBedarf] = @Parm_VkBedarf
    ,[CuGewicht] = @Parm_CuGewicht
    ,[KGruppe] = @Parm_KGruppe
    ,[FloskelJN] = @Parm_FloskelJN
    ,[GAEBxOZ] = RTRIM(@Parm_GAEBxOZ)
    ,[GAEBxTyp] = @Parm_GAEBxTyp
    ,[GAEBxFrM] = @Parm_GAEBxFrM
    ,[AlGewicht] = @Parm_AlGewicht
    ,[SumBrutto] = @Parm_SumBrutto
    ,[ZZGrpNr] = @Parm_ZZGrpNr
    ,[ZZLfdNr] = @Parm_ZZLfdNr
    ,[EPAufgl] = @Parm_EPAufgl
    ,[EpAnteile] = RTRIM(@Parm_EpAnteile)
    ,[VkAnt1] = @Parm_VkAnt1
    ,[VkAnt2] = @Parm_VkAnt2
    ,[VkAnt3] = @Parm_VkAnt3
    ,[VkAnt4] = @Parm_VkAnt4
    ,[Herkunft] = @Parm_Herkunft
    ,[BuchGrp] = RTRIM(@Parm_BuchGrp)
    ,[BezugAuf] = RTRIM(@Parm_BezugAuf)
    ,[BezugBis] = RTRIM(@Parm_BezugBis)
    ,[Flags] = @Parm_Flags
    ,[VkAnt5] = @Parm_VkAnt5
    ,[VkAnt6] = @Parm_VkAnt6
    ,[CVkAnt1] = @Parm_CVkAnt1
    ,[CVkAnt2] = @Parm_CVkAnt2
    ,[CVkAnt3] = @Parm_CVkAnt3
    ,[CVkAnt4] = @Parm_CVkAnt4
    ,[CVkAnt5] = @Parm_CVkAnt5
    ,[CVkAnt6] = @Parm_CVkAnt6
    ,[EkAnteile] = RTRIM(@Parm_EkAnteile)
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_BelPos')
  DROP PROCEDURE [dbo].[up_Sel_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Sel_BelPos]
  @RI integer
AS
SELECT
     [PrjNr]
    ,[BelArt]
    ,[BelNr]
    ,[LfdNr]
    ,[Ebene]
    ,[RefKey]
    ,[SatzArt]
    ,[Nachtrag]
    ,[Bedarf]
    ,[Alternativ]
    ,[Entfaellt]
    ,[Fixed]
    ,[Marked]
    ,[Fremd]
    ,[Vk2JN]
    ,[LohnJN]
    ,[MatJN]
    ,[PosNr]
    ,[ArtNr]
    ,[Ktxt1]
    ,[Menge]
    ,[VkMat]
    ,[VkLohn]
    ,[VkFremd]
    ,[EkMat]
    ,[EkLohn]
    ,[EkFremd]
    ,[RWegZube]
    ,[RWegNe]
    ,[NeFlag]
    ,[EkZube]
    ,[MittelLohn]
    ,[RabattDM]
    ,[RabattVH]
    ,[Zeit]
    ,[Aufwand]
    ,[Me]
    ,[Pe]
    ,[Gebinde]
    ,[AufLohn]
    ,[AufMat]
    ,[Ktxt2]
    ,[Ktxt3]
    ,[KzDrk1]
    ,[KzDrk2]
    ,[TxtNr]
    ,[DrkIndi]
    ,[DrkMenge]
    ,[DrkEP]
    ,[DrkGP]
    ,[DrkLM]
    ,[DrkUpos]
    ,[DrkUposPr]
    ,[DrkUposAbs]
    ,[Vk2Lohn]
    ,[Vk2Mat]
    ,[Brutto]
    ,[Rab1]
    ,[Rab2]
    ,[EkNe]
    ,[OldMLohn]
    ,[Faktor1]
    ,[Faktor2]
    ,[Faktor3]
    ,[ZSAbStart]
    ,[ZSNeutral]
    ,[ZSWieVor]
    ,[DrkFett]
    ,[DrkFF]
    ,[DrkLF]
    ,[KzMwst]
    ,[MengeVA]
    ,[Kst]
    ,[Ktr]
    ,[EGruMat]
    ,[EGruLohn]
    ,[SuSp]
    ,[SuSpTyp]
    ,[AbsMenge]
    ,[EPMat]
    ,[EPLohn]
    ,[EPPos]
    ,[GPPos]
    ,[AbsGP]
    ,[ParentRef]
    ,[Expanded]
    ,[Visible]
    ,[SuSpValid]
    ,[Dropped]
    ,[Saved]
    ,[EkSonstig]
    ,[VkBedarf]
    ,[CuGewicht]
    ,[KGruppe]
    ,[FloskelJN]
    ,[GAEBxOZ]
    ,[GAEBxTyp]
    ,[GAEBxFrM]
    ,[AlGewicht]
    ,[SumBrutto]
    ,[ZZGrpNr]
    ,[ZZLfdNr]
    ,[EPAufgl]
    ,[EpAnteile]
    ,[VkAnt1]
    ,[VkAnt2]
    ,[VkAnt3]
    ,[VkAnt4]
    ,[Herkunft]
    ,[BuchGrp]
    ,[BezugAuf]
    ,[BezugBis]
    ,[Flags]
    ,[VkAnt5]
    ,[VkAnt6]
    ,[CVkAnt1]
    ,[CVkAnt2]
    ,[CVkAnt3]
    ,[CVkAnt4]
    ,[CVkAnt5]
    ,[CVkAnt6]
    ,[EkAnteile]
  FROM [dbo].[ut_BelPos]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_BelPos')
  DROP PROCEDURE [dbo].[up_Del_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Del_BelPos]
  @RI integer
AS
  DELETE FROM [dbo].[ut_BelPos] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_BelPos')
  DROP PROCEDURE [dbo].[up_Reorg_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Reorg_BelPos]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_BelPos] 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_BelPos] 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_BelPos] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_BelPos')
  DROP PROCEDURE [dbo].[up_Append_BelPos]
GO
CREATE PROCEDURE [dbo].[up_Append_BelPos]
  @Parm_PrjNr char(8)
 ,@Parm_BelArt char(2)
 ,@Parm_BelNr char(8)
 ,@Parm_LfdNr char(6)
 ,@Parm_Ebene integer
 ,@Parm_RefKey char(6)
 ,@Parm_SatzArt integer
 ,@Parm_Nachtrag integer
 ,@Parm_Bedarf tinyint
 ,@Parm_Alternativ tinyint
 ,@Parm_Entfaellt tinyint
 ,@Parm_Fixed tinyint
 ,@Parm_Marked tinyint
 ,@Parm_Fremd tinyint
 ,@Parm_Vk2JN tinyint
 ,@Parm_LohnJN tinyint
 ,@Parm_MatJN tinyint
 ,@Parm_PosNr char(20)
 ,@Parm_ArtNr char(20)
 ,@Parm_Ktxt1 char(50)
 ,@Parm_Menge float
 ,@Parm_VkMat float
 ,@Parm_VkLohn float
 ,@Parm_VkFremd float
 ,@Parm_EkMat float
 ,@Parm_EkLohn float
 ,@Parm_EkFremd float
 ,@Parm_RWegZube integer
 ,@Parm_RWegNe integer
 ,@Parm_NeFlag tinyint
 ,@Parm_EkZube float
 ,@Parm_MittelLohn float
 ,@Parm_RabattDM float
 ,@Parm_RabattVH float
 ,@Parm_Zeit float
 ,@Parm_Aufwand float
 ,@Parm_Me char(6)
 ,@Parm_Pe char(2)
 ,@Parm_Gebinde float
 ,@Parm_AufLohn float
 ,@Parm_AufMat float
 ,@Parm_Ktxt2 char(50)
 ,@Parm_Ktxt3 char(50)
 ,@Parm_KzDrk1 integer
 ,@Parm_KzDrk2 integer
 ,@Parm_TxtNr char(20)
 ,@Parm_DrkIndi tinyint
 ,@Parm_DrkMenge tinyint
 ,@Parm_DrkEP tinyint
 ,@Parm_DrkGP tinyint
 ,@Parm_DrkLM tinyint
 ,@Parm_DrkUpos tinyint
 ,@Parm_DrkUposPr tinyint
 ,@Parm_DrkUposAbs tinyint
 ,@Parm_Vk2Lohn float
 ,@Parm_Vk2Mat float
 ,@Parm_Brutto float
 ,@Parm_Rab1 float
 ,@Parm_Rab2 float
 ,@Parm_EkNe float
 ,@Parm_OldMLohn tinyint
 ,@Parm_Faktor1 float
 ,@Parm_Faktor2 float
 ,@Parm_Faktor3 float
 ,@Parm_ZSAbStart tinyint
 ,@Parm_ZSNeutral tinyint
 ,@Parm_ZSWieVor tinyint
 ,@Parm_DrkFett tinyint
 ,@Parm_DrkFF tinyint
 ,@Parm_DrkLF tinyint
 ,@Parm_KzMwst integer
 ,@Parm_MengeVA float
 ,@Parm_Kst char(20)
 ,@Parm_Ktr char(20)
 ,@Parm_EGruMat char(3)
 ,@Parm_EGruLohn char(3)
 ,@Parm_SuSp char(20)
 ,@Parm_SuSpTyp integer
 ,@Parm_AbsMenge float
 ,@Parm_EPMat float
 ,@Parm_EPLohn float
 ,@Parm_EPPos float
 ,@Parm_GPPos float
 ,@Parm_AbsGP float
 ,@Parm_ParentRef char(6)
 ,@Parm_Expanded tinyint
 ,@Parm_Visible tinyint
 ,@Parm_SuSpValid tinyint
 ,@Parm_Dropped tinyint
 ,@Parm_Saved tinyint
 ,@Parm_EkSonstig float
 ,@Parm_VkBedarf float
 ,@Parm_CuGewicht float
 ,@Parm_KGruppe integer
 ,@Parm_FloskelJN tinyint
 ,@Parm_GAEBxOZ char(20)
 ,@Parm_GAEBxTyp integer
 ,@Parm_GAEBxFrM tinyint
 ,@Parm_AlGewicht float
 ,@Parm_SumBrutto float
 ,@Parm_ZZGrpNr integer
 ,@Parm_ZZLfdNr integer
 ,@Parm_EPAufgl tinyint
 ,@Parm_EpAnteile char(18)
 ,@Parm_VkAnt1 float
 ,@Parm_VkAnt2 float
 ,@Parm_VkAnt3 float
 ,@Parm_VkAnt4 float
 ,@Parm_Herkunft integer
 ,@Parm_BuchGrp char(10)
 ,@Parm_BezugAuf char(6)
 ,@Parm_BezugBis char(6)
 ,@Parm_Flags integer
 ,@Parm_VkAnt5 float
 ,@Parm_VkAnt6 float
 ,@Parm_CVkAnt1 float
 ,@Parm_CVkAnt2 float
 ,@Parm_CVkAnt3 float
 ,@Parm_CVkAnt4 float
 ,@Parm_CVkAnt5 float
 ,@Parm_CVkAnt6 float
 ,@Parm_EkAnteile char(168)
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_BelPos])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_BelPos] (
    RecId
   ,[PrjNr]
   ,[BelArt]
   ,[BelNr]
   ,[LfdNr]
   ,[Ebene]
   ,[RefKey]
   ,[SatzArt]
   ,[Nachtrag]
   ,[Bedarf]
   ,[Alternativ]
   ,[Entfaellt]
   ,[Fixed]
   ,[Marked]
   ,[Fremd]
   ,[Vk2JN]
   ,[LohnJN]
   ,[MatJN]
   ,[PosNr]
   ,[ArtNr]
   ,[Ktxt1]
   ,[Menge]
   ,[VkMat]
   ,[VkLohn]
   ,[VkFremd]
   ,[EkMat]
   ,[EkLohn]
   ,[EkFremd]
   ,[RWegZube]
   ,[RWegNe]
   ,[NeFlag]
   ,[EkZube]
   ,[MittelLohn]
   ,[RabattDM]
   ,[RabattVH]
   ,[Zeit]
   ,[Aufwand]
   ,[Me]
   ,[Pe]
   ,[Gebinde]
   ,[AufLohn]
   ,[AufMat]
   ,[Ktxt2]
   ,[Ktxt3]
   ,[KzDrk1]
   ,[KzDrk2]
   ,[TxtNr]
   ,[DrkIndi]
   ,[DrkMenge]
   ,[DrkEP]
   ,[DrkGP]
   ,[DrkLM]
   ,[DrkUpos]
   ,[DrkUposPr]
   ,[DrkUposAbs]
   ,[Vk2Lohn]
   ,[Vk2Mat]
   ,[Brutto]
   ,[Rab1]
   ,[Rab2]
   ,[EkNe]
   ,[OldMLohn]
   ,[Faktor1]
   ,[Faktor2]
   ,[Faktor3]
   ,[ZSAbStart]
   ,[ZSNeutral]
   ,[ZSWieVor]
   ,[DrkFett]
   ,[DrkFF]
   ,[DrkLF]
   ,[KzMwst]
   ,[MengeVA]
   ,[Kst]
   ,[Ktr]
   ,[EGruMat]
   ,[EGruLohn]
   ,[SuSp]
   ,[SuSpTyp]
   ,[AbsMenge]
   ,[EPMat]
   ,[EPLohn]
   ,[EPPos]
   ,[GPPos]
   ,[AbsGP]
   ,[ParentRef]
   ,[Expanded]
   ,[Visible]
   ,[SuSpValid]
   ,[Dropped]
   ,[Saved]
   ,[EkSonstig]
   ,[VkBedarf]
   ,[CuGewicht]
   ,[KGruppe]
   ,[FloskelJN]
   ,[GAEBxOZ]
   ,[GAEBxTyp]
   ,[GAEBxFrM]
   ,[AlGewicht]
   ,[SumBrutto]
   ,[ZZGrpNr]
   ,[ZZLfdNr]
   ,[EPAufgl]
   ,[EpAnteile]
   ,[VkAnt1]
   ,[VkAnt2]
   ,[VkAnt3]
   ,[VkAnt4]
   ,[Herkunft]
   ,[BuchGrp]
   ,[BezugAuf]
   ,[BezugBis]
   ,[Flags]
   ,[VkAnt5]
   ,[VkAnt6]
   ,[CVkAnt1]
   ,[CVkAnt2]
   ,[CVkAnt3]
   ,[CVkAnt4]
   ,[CVkAnt5]
   ,[CVkAnt6]
   ,[EkAnteile]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_PrjNr)
   ,RTRIM(@Parm_BelArt)
   ,RTRIM(@Parm_BelNr)
   ,RTRIM(@Parm_LfdNr)
   ,@Parm_Ebene
   ,RTRIM(@Parm_RefKey)
   ,@Parm_SatzArt
   ,@Parm_Nachtrag
   ,@Parm_Bedarf
   ,@Parm_Alternativ
   ,@Parm_Entfaellt
   ,@Parm_Fixed
   ,@Parm_Marked
   ,@Parm_Fremd
   ,@Parm_Vk2JN
   ,@Parm_LohnJN
   ,@Parm_MatJN
   ,RTRIM(@Parm_PosNr)
   ,RTRIM(@Parm_ArtNr)
   ,RTRIM(@Parm_Ktxt1)
   ,@Parm_Menge
   ,@Parm_VkMat
   ,@Parm_VkLohn
   ,@Parm_VkFremd
   ,@Parm_EkMat
   ,@Parm_EkLohn
   ,@Parm_EkFremd
   ,@Parm_RWegZube
   ,@Parm_RWegNe
   ,@Parm_NeFlag
   ,@Parm_EkZube
   ,@Parm_MittelLohn
   ,@Parm_RabattDM
   ,@Parm_RabattVH
   ,@Parm_Zeit
   ,@Parm_Aufwand
   ,RTRIM(@Parm_Me)
   ,RTRIM(@Parm_Pe)
   ,@Parm_Gebinde
   ,@Parm_AufLohn
   ,@Parm_AufMat
   ,RTRIM(@Parm_Ktxt2)
   ,RTRIM(@Parm_Ktxt3)
   ,@Parm_KzDrk1
   ,@Parm_KzDrk2
   ,RTRIM(@Parm_TxtNr)
   ,@Parm_DrkIndi
   ,@Parm_DrkMenge
   ,@Parm_DrkEP
   ,@Parm_DrkGP
   ,@Parm_DrkLM
   ,@Parm_DrkUpos
   ,@Parm_DrkUposPr
   ,@Parm_DrkUposAbs
   ,@Parm_Vk2Lohn
   ,@Parm_Vk2Mat
   ,@Parm_Brutto
   ,@Parm_Rab1
   ,@Parm_Rab2
   ,@Parm_EkNe
   ,@Parm_OldMLohn
   ,@Parm_Faktor1
   ,@Parm_Faktor2
   ,@Parm_Faktor3
   ,@Parm_ZSAbStart
   ,@Parm_ZSNeutral
   ,@Parm_ZSWieVor
   ,@Parm_DrkFett
   ,@Parm_DrkFF
   ,@Parm_DrkLF
   ,@Parm_KzMwst
   ,@Parm_MengeVA
   ,RTRIM(@Parm_Kst)
   ,RTRIM(@Parm_Ktr)
   ,RTRIM(@Parm_EGruMat)
   ,RTRIM(@Parm_EGruLohn)
   ,RTRIM(@Parm_SuSp)
   ,@Parm_SuSpTyp
   ,@Parm_AbsMenge
   ,@Parm_EPMat
   ,@Parm_EPLohn
   ,@Parm_EPPos
   ,@Parm_GPPos
   ,@Parm_AbsGP
   ,RTRIM(@Parm_ParentRef)
   ,@Parm_Expanded
   ,@Parm_Visible
   ,@Parm_SuSpValid
   ,@Parm_Dropped
   ,@Parm_Saved
   ,@Parm_EkSonstig
   ,@Parm_VkBedarf
   ,@Parm_CuGewicht
   ,@Parm_KGruppe
   ,@Parm_FloskelJN
   ,RTRIM(@Parm_GAEBxOZ)
   ,@Parm_GAEBxTyp
   ,@Parm_GAEBxFrM
   ,@Parm_AlGewicht
   ,@Parm_SumBrutto
   ,@Parm_ZZGrpNr
   ,@Parm_ZZLfdNr
   ,@Parm_EPAufgl
   ,RTRIM(@Parm_EpAnteile)
   ,@Parm_VkAnt1
   ,@Parm_VkAnt2
   ,@Parm_VkAnt3
   ,@Parm_VkAnt4
   ,@Parm_Herkunft
   ,RTRIM(@Parm_BuchGrp)
   ,RTRIM(@Parm_BezugAuf)
   ,RTRIM(@Parm_BezugBis)
   ,@Parm_Flags
   ,@Parm_VkAnt5
   ,@Parm_VkAnt6
   ,@Parm_CVkAnt1
   ,@Parm_CVkAnt2
   ,@Parm_CVkAnt3
   ,@Parm_CVkAnt4
   ,@Parm_CVkAnt5
   ,@Parm_CVkAnt6
   ,RTRIM(@Parm_EkAnteile)
       )
  IF @@ERROR = 0
  BEGIN
    SELECT @NeueId AS RecId
    RETURN
  END
  SELECT 0 AS RecId
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_BelPos')
  DROP PROCEDURE [dbo].[up_TrSel_BelPos]
GO
CREATE PROCEDURE [dbo].[up_TrSel_BelPos]
AS
  SELECT   RecId,
      LTRIM(RTRIM([PrjNr]))
      +LTRIM(RTRIM([BelArt]))
      +LTRIM(RTRIM([BelNr]))
      +LTRIM(RTRIM([LfdNr]))
      +LTRIM(RTRIM([RefKey]))
      +LTRIM(RTRIM([PosNr]))
      +LTRIM(RTRIM([ArtNr]))
      +LTRIM(RTRIM([Ktxt1]))
      +LTRIM(RTRIM([Me]))
      +LTRIM(RTRIM([Pe]))
      +LTRIM(RTRIM([Ktxt2]))
      +LTRIM(RTRIM([Ktxt3]))
      +LTRIM(RTRIM([TxtNr]))
      +LTRIM(RTRIM([Kst]))
      +LTRIM(RTRIM([Ktr]))
      +LTRIM(RTRIM([EGruMat]))
      +LTRIM(RTRIM([EGruLohn]))
      +LTRIM(RTRIM([SuSp]))
      +LTRIM(RTRIM([ParentRef]))
      +LTRIM(RTRIM([GAEBxOZ]))
      +LTRIM(RTRIM([EpAnteile]))
      +LTRIM(RTRIM([BuchGrp]))
      +LTRIM(RTRIM([BezugAuf]))
      +LTRIM(RTRIM([BezugBis]))
      +LTRIM(RTRIM([EkAnteile]))
    AS Data
  FROM     [dbo].[ut_BelPos]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_BelPos_Keys]
( [Key00_Filter],[Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key00')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key00]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key00_Filter] = 1 ORDER BY [Key00_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key00]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key00_Filter] = 1 ORDER BY [Key00_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key00] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key00_Filter] = 1 AND [Key00_Value] > (SELECT [Key00_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key00] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key00_Filter] = 1 AND [Key00_Value] < (SELECT [Key00_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key00_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key00] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key00_Filter] = 1 AND [Key00_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key00_Value] DESC
GO

CREATE INDEX [Ik_Key01] ON [dbo].[ut_BelPos_Keys]
( [Key01_Filter],[Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key01')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key01]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key01_Filter] = 1 ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key01]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key01_Filter] = 1 ORDER BY [Key01_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key01_Filter] = 1 AND [Key01_Value] > (SELECT [Key01_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key01] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key01_Filter] = 1 AND [Key01_Value] < (SELECT [Key01_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key01_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key01] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key01_Filter] = 1 AND [Key01_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key01_Value] DESC
GO

CREATE INDEX [Ik_Key02] ON [dbo].[ut_BelPos_Keys]
( [Key02_Filter],[Key02_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key02]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key02')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key02]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key02_Filter] = 1 ORDER BY [Key02_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key02]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key02_Filter] = 1 ORDER BY [Key02_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key02] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key02_Filter] = 1 AND [Key02_Value] > (SELECT [Key02_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key02] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key02_Filter] = 1 AND [Key02_Value] < (SELECT [Key02_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key02_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key02] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key02_Filter] = 1 AND [Key02_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key02_Value] DESC
GO

CREATE INDEX [Ik_Key03] ON [dbo].[ut_BelPos_Keys]
( [Key03_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key03]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key03')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key03]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key04] ON [dbo].[ut_BelPos_Keys]
( [Key04_Filter],[Key04_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key04]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key04')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key04]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key04_Filter] = 1 ORDER BY [Key04_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key04]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key04_Filter] = 1 ORDER BY [Key04_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key04] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key04_Filter] = 1 AND [Key04_Value] > (SELECT [Key04_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key04] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key04_Filter] = 1 AND [Key04_Value] < (SELECT [Key04_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key04_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key04] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key04_Filter] = 1 AND [Key04_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key04_Value] DESC
GO

CREATE INDEX [Ik_Key05] ON [dbo].[ut_BelPos_Keys]
( [Key05_Filter],[Key05_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key05]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key05')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key05]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key05_Filter] = 1 ORDER BY [Key05_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key05]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key05_Filter] = 1 ORDER BY [Key05_Value] DESC
GO

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

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key05] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key05_Filter] = 1 AND [Key05_Value] > (SELECT [Key05_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key05] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key05_Filter] = 1 AND [Key05_Value] < (SELECT [Key05_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key05_Value] DESC
GO

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

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

CREATE INDEX [Ik_Key06] ON [dbo].[ut_BelPos_Keys]
( [Key06_Filter],[Key06_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key06]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key06')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key06]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 ORDER BY [Key06_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key06]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 ORDER BY [Key06_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key06] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 AND [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key06] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 AND [Key06_Value] < (SELECT [Key06_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key06] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 AND [Key06_Value] > (SELECT [Key06_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key06] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 AND [Key06_Value] < (SELECT [Key06_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key06_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key06] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key06_Filter] = 1 AND [Key06_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key06_Value] DESC
GO

CREATE INDEX [Ik_Key07] ON [dbo].[ut_BelPos_Keys]
( [Key07_Filter],[Key07_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key07]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key07')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key07]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 ORDER BY [Key07_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key07]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 ORDER BY [Key07_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key07] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 AND [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key07] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 AND [Key07_Value] < (SELECT [Key07_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key07] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 AND [Key07_Value] > (SELECT [Key07_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key07] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 AND [Key07_Value] < (SELECT [Key07_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key07_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key07] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key07_Filter] = 1 AND [Key07_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key07_Value] DESC
GO

CREATE INDEX [Ik_Key08] ON [dbo].[ut_BelPos_Keys]
( [Key08_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key08]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key08')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key08]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys] ORDER BY [Key08_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key08]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys] ORDER BY [Key08_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key08] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key08] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key08_Value] > (SELECT [Key08_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key08_Value]
GO

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

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

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

CREATE INDEX [Ik_Key09] ON [dbo].[ut_BelPos_Keys]
( [Key09_Filter],[Key09_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key09]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key09')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key09]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key09]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 ORDER BY [Key09_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key09]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 ORDER BY [Key09_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key09] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 AND [Key09_Value] > (SELECT [Key09_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key09] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 AND [Key09_Value] < (SELECT [Key09_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key09] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 AND [Key09_Value] > (SELECT [Key09_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key09] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 AND [Key09_Value] < (SELECT [Key09_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key09_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key09] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key09_Filter] = 1 AND [Key09_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key09_Value] DESC
GO

CREATE INDEX [Ik_Key10] ON [dbo].[ut_BelPos_Keys]
( [Key10_Filter],[Key10_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key10]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key10')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key10]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key10]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 ORDER BY [Key10_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key10]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 ORDER BY [Key10_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key10] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 AND [Key10_Value] > (SELECT [Key10_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key10] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 AND [Key10_Value] < (SELECT [Key10_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key10] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 AND [Key10_Value] > (SELECT [Key10_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key10] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 AND [Key10_Value] < (SELECT [Key10_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key10_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key10] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key10_Filter] = 1 AND [Key10_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key10_Value] DESC
GO

CREATE INDEX [Ik_Key11] ON [dbo].[ut_BelPos_Keys]
( [Key11_Filter],[Key11_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key11]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key11')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key11]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key11]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 ORDER BY [Key11_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key11]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 ORDER BY [Key11_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key11] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 AND [Key11_Value] > (SELECT [Key11_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key11] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 AND [Key11_Value] < (SELECT [Key11_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key11] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 AND [Key11_Value] > (SELECT [Key11_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key11] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 AND [Key11_Value] < (SELECT [Key11_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key11_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key11] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key11_Filter] = 1 AND [Key11_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key11_Value] DESC
GO

CREATE INDEX [Ik_Key12] ON [dbo].[ut_BelPos_Keys]
( [Key12_Filter],[Key12_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key12]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key12')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key12]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key12]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 ORDER BY [Key12_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key12]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 ORDER BY [Key12_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key12] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 AND [Key12_Value] > (SELECT [Key12_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key12_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key12] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 AND [Key12_Value] < (SELECT [Key12_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key12_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key12] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 AND [Key12_Value] > (SELECT [Key12_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key12_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key12] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 AND [Key12_Value] < (SELECT [Key12_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key12_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key12] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key12_Filter] = 1 AND [Key12_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key12_Value] DESC
GO

CREATE INDEX [Ik_Key13] ON [dbo].[ut_BelPos_Keys]
( [Key13_Filter],[Key13_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_First_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_Last_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_Prior_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_Next_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_Prior50_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_Next50_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_FindL_BelPos_Key13]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_BelPos_Key13')
  DROP PROCEDURE [dbo].[up_FindF_BelPos_Key13]
GO

CREATE PROCEDURE [dbo].[up_First_BelPos_Key13]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 ORDER BY [Key13_Value]
GO

CREATE PROCEDURE [dbo].[up_Last_BelPos_Key13]
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 ORDER BY [Key13_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next_BelPos_Key13] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 AND [Key13_Value] > (SELECT [Key13_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key13_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior_BelPos_Key13] @mRecNo integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 AND [Key13_Value] < (SELECT [Key13_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key13_Value] DESC
GO

CREATE PROCEDURE [dbo].[up_Next50_BelPos_Key13] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 AND [Key13_Value] > (SELECT [Key13_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key13_Value]
GO

CREATE PROCEDURE [dbo].[up_Prior50_BelPos_Key13] @mRecNo integer
AS
  SELECT TOP 50 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 AND [Key13_Value] < (SELECT [Key13_Value] FROM [dbo].[ut_BelPos_Keys] WHERE [DataRecId] = @mRecNo)
  ORDER BY [Key13_Value] DESC
GO

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

CREATE PROCEDURE [dbo].[up_FindL_BelPos_Key13] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_BelPos_Keys]
  WHERE [Key13_Filter] = 1 AND [Key13_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key13_Value] DESC
GO

