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

IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_Adressen')
BEGIN
CREATE TABLE [dbo].[ut_Adressen]
(
  [RecId]  integer NOT NULL
 ,[DESTDEBNR] char(15) DEFAULT ''
 ,[DESTTYP] char(2) DEFAULT ''
 ,[SUCHEN] char(40) DEFAULT ''
 ,[Anrede] varchar(40) DEFAULT ''
 ,[VorName] varchar(40) DEFAULT ''
 ,[Name1] char(40) DEFAULT ''
 ,[Name2] varchar(40) DEFAULT ''
 ,[Branche] varchar(40) DEFAULT ''
 ,[Strasse] varchar(40) DEFAULT ''
 ,[Ort] char(40) DEFAULT ''
 ,[Land] varchar(6) DEFAULT ''
 ,[Plz] char(10) DEFAULT ''
 ,[PsfPlz] char(10) DEFAULT ''
 ,[Psf] char(15) DEFAULT ''
 ,[PlzGrossEm] char(10) DEFAULT ''
 ,[zuHaenden] varchar(40) DEFAULT ''
 ,[zuHaeAnre] varchar(40) DEFAULT ''
 ,[BrAnrede] varchar(40) DEFAULT ''
 ,[BrGruss] varchar(40) DEFAULT ''
 ,[Telefon1] varchar(20) DEFAULT ''
 ,[Tel1Kurz] varchar(20) DEFAULT ''
 ,[Telefon2] varchar(20) DEFAULT ''
 ,[Tel2Kurz] varchar(20) DEFAULT ''
 ,[Telefon3] varchar(20) DEFAULT ''
 ,[Tel3Kurz] varchar(20) DEFAULT ''
 ,[FaxNummer] varchar(20) DEFAULT ''
 ,[FaxKurz] varchar(20) DEFAULT ''
 ,[EMail] varchar(80) DEFAULT ''
 ,[SpKzJn] tinyint DEFAULT 0
 ,[Selection1] varchar(15) DEFAULT ''
 ,[Selection2] varchar(15) DEFAULT ''
 ,[DatumAnlag] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[DatumAende] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
 ,[FibuKonto] char(15) DEFAULT ''
 ,[KzDivers] tinyint DEFAULT 0
 ,[KzAdr] char(1) DEFAULT ''
 ,[KzKh] tinyint DEFAULT 0
 ,[Kondition] integer DEFAULT 0
 ,[MahnenJN] tinyint DEFAULT 0
 ,[MahnKondit] varchar(50) DEFAULT ''
 ,[SkontoTole] varchar(50) DEFAULT ''
 ,[Blz1] varchar(11) DEFAULT ''
 ,[KontoNr1] varchar(15) DEFAULT ''
 ,[Blz2] varchar(11) DEFAULT ''
 ,[KontoNr2] varchar(15) DEFAULT ''
 ,[Blz3] varchar(11) DEFAULT ''
 ,[KontoNr3] varchar(15) DEFAULT ''
 ,[KreditLimi] float DEFAULT 0
 ,[UstId1] varchar(15) DEFAULT ''
 ,[Dokument] varchar(42) DEFAULT ''
 ,[Info1] char(20) DEFAULT ''
 ,[Info2] char(20) DEFAULT ''
 ,[Info3] char(20) DEFAULT ''
 ,[Info4] char(20) DEFAULT ''
 ,[LkzImport] char(2) DEFAULT ''
 ,[KzPreisPfl] tinyint DEFAULT 0
 ,[LiefKdNrD] char(20) DEFAULT ''
 ,[LiefKdNrE] char(20) DEFAULT ''
 ,[KostSt] char(20) DEFAULT ''
 ,[AbrGruppe] integer DEFAULT 0
 ,[SollStd] float DEFAULT 0
 ,[BaGruppe] char(2) DEFAULT ''
 ,[EkLohn] float DEFAULT 0
 ,[Annr] char(4) DEFAULT ''
 ,[Res4NG2] varchar(28) DEFAULT ''
 ,[BruttoLohn] float DEFAULT 0
 ,[HomePage] varchar(80) DEFAULT ''
 ,[LandName] varchar(40) DEFAULT ''
 ,[RefTo] char(15) DEFAULT ''
 ,[SWIFT_BIC] char(11) DEFAULT ''
 ,[IBAN] char(34) DEFAULT ''
 ,[DatenHerk] varchar(30) DEFAULT ''
 ,[SyncState] integer DEFAULT 0
 ,[EDocType] char(10) DEFAULT ''
 ,[KontoInh] varchar(40) DEFAULT ''
 ,[PeppolAddr] varchar(40) DEFAULT ''
  CONSTRAINT [Pk_Adressen]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO

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

-- add new fields
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTDEBNR')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [DESTDEBNR] char(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTTYP')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [DESTTYP] 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_Adressen' and sc.[name] = 'SUCHEN')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SUCHEN] char(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Anrede')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Anrede] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'VorName')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [VorName] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Name1] char(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Name2] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Branche')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Branche] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Strasse')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Strasse] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Ort')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Ort] char(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Land')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Land] varchar(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_Adressen' and sc.[name] = 'Plz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Plz] 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_Adressen' and sc.[name] = 'PsfPlz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [PsfPlz] 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_Adressen' and sc.[name] = 'Psf')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Psf] char(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PlzGrossEm')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [PlzGrossEm] 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_Adressen' and sc.[name] = 'zuHaenden')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [zuHaenden] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaeAnre')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [zuHaeAnre] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrAnrede')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [BrAnrede] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrGruss')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [BrGruss] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Telefon1] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel1Kurz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Tel1Kurz] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Telefon2] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel2Kurz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Tel2Kurz] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon3')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Telefon3] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel3Kurz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Tel3Kurz] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxNummer')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [FaxNummer] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxKurz')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [FaxKurz] varchar(20) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EMail')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [EMail] varchar(80) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SpKzJn')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SpKzJn] 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_Adressen' and sc.[name] = 'Selection1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Selection1] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Selection2] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatumAnlag')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [DatumAnlag] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatumAende')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [DatumAende] datetime NOT NULL DEFAULT CONVERT(datetime,'1900-01-01',120)
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FibuKonto')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [FibuKonto] char(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzDivers')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KzDivers] 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_Adressen' and sc.[name] = 'KzAdr')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KzAdr] char(1) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzKh')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KzKh] 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_Adressen' and sc.[name] = 'Kondition')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Kondition] 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_Adressen' and sc.[name] = 'MahnenJN')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [MahnenJN] 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_Adressen' and sc.[name] = 'MahnKondit')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [MahnKondit] varchar(50) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SkontoTole')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SkontoTole] varchar(50) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Blz1] varchar(11) 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_Adressen' and sc.[name] = 'KontoNr1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KontoNr1] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Blz2] varchar(11) 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_Adressen' and sc.[name] = 'KontoNr2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KontoNr2] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz3')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Blz3] varchar(11) 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_Adressen' and sc.[name] = 'KontoNr3')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KontoNr3] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KreditLimi')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KreditLimi] 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_Adressen' and sc.[name] = 'UstId1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [UstId1] varchar(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Dokument')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Dokument] varchar(42) 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_Adressen' and sc.[name] = 'Info1')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Info1] 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_Adressen' and sc.[name] = 'Info2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Info2] 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_Adressen' and sc.[name] = 'Info3')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Info3] 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_Adressen' and sc.[name] = 'Info4')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Info4] 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_Adressen' and sc.[name] = 'LkzImport')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [LkzImport] 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_Adressen' and sc.[name] = 'KzPreisPfl')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KzPreisPfl] 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_Adressen' and sc.[name] = 'LiefKdNrD')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [LiefKdNrD] 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_Adressen' and sc.[name] = 'LiefKdNrE')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [LiefKdNrE] 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_Adressen' and sc.[name] = 'KostSt')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KostSt] 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_Adressen' and sc.[name] = 'AbrGruppe')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [AbrGruppe] 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_Adressen' and sc.[name] = 'SollStd')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SollStd] 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_Adressen' and sc.[name] = 'BaGruppe')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [BaGruppe] 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_Adressen' and sc.[name] = 'EkLohn')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] 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_Adressen' and sc.[name] = 'Annr')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Annr] char(4) 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_Adressen' and sc.[name] = 'Res4NG2')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [Res4NG2] varchar(28) 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_Adressen' and sc.[name] = 'BruttoLohn')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [BruttoLohn] 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_Adressen' and sc.[name] = 'HomePage')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [HomePage] varchar(80) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LandName')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [LandName] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'RefTo')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [RefTo] char(15) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SWIFT_BIC')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SWIFT_BIC] char(11) 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_Adressen' and sc.[name] = 'IBAN')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [IBAN] char(34) 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_Adressen' and sc.[name] = 'DatenHerk')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [DatenHerk] varchar(30) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SyncState')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [SyncState] 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_Adressen' and sc.[name] = 'EDocType')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [EDocType] 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_Adressen' and sc.[name] = 'KontoInh')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [KontoInh] varchar(40) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PeppolAddr')
BEGIN
  ALTER TABLE [dbo].[ut_Adressen] ADD [PeppolAddr] varchar(40) NOT NULL DEFAULT ''
END
GO

-- check lengths of text fields
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTDEBNR'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTDEBNR'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DESTDEBNR] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTDEBNR'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTDEBNR'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DESTDEBNR] varchar(15)
END
GO
IF (2 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTTYP'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTTYP'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DESTTYP] char(2)
END
GO
IF (2 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTTYP'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DESTTYP'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DESTTYP] varchar(2)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SUCHEN'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SUCHEN'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SUCHEN] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SUCHEN'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SUCHEN'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SUCHEN] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Anrede'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Anrede'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Anrede] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Anrede'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Anrede'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Anrede] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'VorName'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'VorName'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [VorName] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'VorName'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'VorName'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [VorName] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Name1] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Name1] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Name2] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Name2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Name2] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Branche'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Branche'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Branche] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Branche'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Branche'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Branche] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Strasse'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Strasse'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Strasse] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Strasse'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Strasse'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Strasse] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Ort'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Ort'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Ort] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Ort'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Ort'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Ort] varchar(40)
END
GO
IF (6 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Land'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Land'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Land] char(6)
END
GO
IF (6 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Land'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Land'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Land] varchar(6)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Plz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Plz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Plz] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Plz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Plz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Plz] varchar(10)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PsfPlz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PsfPlz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PsfPlz] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PsfPlz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PsfPlz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PsfPlz] varchar(10)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Psf'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Psf'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Psf] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Psf'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Psf'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Psf] varchar(15)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PlzGrossEm'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PlzGrossEm'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PlzGrossEm] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PlzGrossEm'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PlzGrossEm'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PlzGrossEm] varchar(10)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaenden'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaenden'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [zuHaenden] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaenden'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaenden'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [zuHaenden] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaeAnre'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaeAnre'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [zuHaeAnre] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaeAnre'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'zuHaeAnre'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [zuHaeAnre] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrAnrede'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrAnrede'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BrAnrede] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrAnrede'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrAnrede'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BrAnrede] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrGruss'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrGruss'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BrGruss] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrGruss'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BrGruss'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BrGruss] varchar(40)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon1] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon1] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel1Kurz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel1Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel1Kurz] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel1Kurz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel1Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel1Kurz] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon2] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon2] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel2Kurz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel2Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel2Kurz] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel2Kurz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel2Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel2Kurz] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon3] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Telefon3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Telefon3] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel3Kurz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel3Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel3Kurz] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel3Kurz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Tel3Kurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Tel3Kurz] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxNummer'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxNummer'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FaxNummer] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxNummer'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxNummer'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FaxNummer] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxKurz'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxKurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FaxKurz] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxKurz'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FaxKurz'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FaxKurz] varchar(20)
END
GO
IF (80 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EMail'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EMail'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [EMail] char(80)
END
GO
IF (80 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EMail'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EMail'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [EMail] varchar(80)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Selection1] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Selection1] varchar(15)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Selection2] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Selection2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Selection2] varchar(15)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FibuKonto'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FibuKonto'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FibuKonto] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FibuKonto'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'FibuKonto'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [FibuKonto] varchar(15)
END
GO
IF (1 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzAdr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzAdr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KzAdr] char(1)
END
GO
IF (1 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzAdr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KzAdr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KzAdr] varchar(1)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'MahnKondit'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'MahnKondit'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [MahnKondit] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'MahnKondit'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'MahnKondit'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [MahnKondit] varchar(50)
END
GO
IF (50 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SkontoTole'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SkontoTole'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SkontoTole] char(50)
END
GO
IF (50 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SkontoTole'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SkontoTole'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SkontoTole] varchar(50)
END
GO
IF (11 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz1] char(11)
END
GO
IF (11 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz1] varchar(11)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr1] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr1] varchar(15)
END
GO
IF (11 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz2] char(11)
END
GO
IF (11 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz2] varchar(11)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr2] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr2] varchar(15)
END
GO
IF (11 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz3] char(11)
END
GO
IF (11 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Blz3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Blz3] varchar(11)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr3] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoNr3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoNr3] varchar(15)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'UstId1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'UstId1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [UstId1] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'UstId1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'UstId1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [UstId1] varchar(15)
END
GO
IF (42 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Dokument'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Dokument'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Dokument] char(42)
END
GO
IF (42 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Dokument'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Dokument'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Dokument] varchar(42)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info1'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info1] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info1'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info1'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info1] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info2] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info2] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info3'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info3] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info3'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info3'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info3] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info4'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info4'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info4] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info4'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Info4'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Info4] varchar(20)
END
GO
IF (2 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LkzImport'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LkzImport'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LkzImport] char(2)
END
GO
IF (2 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LkzImport'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LkzImport'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LkzImport] varchar(2)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrD'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrD'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LiefKdNrD] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrD'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrD'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LiefKdNrD] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrE'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrE'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LiefKdNrE] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrE'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LiefKdNrE'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LiefKdNrE] varchar(20)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KostSt'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KostSt'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KostSt] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KostSt'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KostSt'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KostSt] varchar(20)
END
GO
IF (2 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BaGruppe'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BaGruppe'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BaGruppe] char(2)
END
GO
IF (2 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BaGruppe'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'BaGruppe'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [BaGruppe] varchar(2)
END
GO
IF (4 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Annr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Annr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Annr] char(4)
END
GO
IF (4 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Annr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Annr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Annr] varchar(4)
END
GO
IF (28 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Res4NG2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Res4NG2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Res4NG2] char(28)
END
GO
IF (28 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Res4NG2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'Res4NG2'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [Res4NG2] varchar(28)
END
GO
IF (80 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'HomePage'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'HomePage'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [HomePage] char(80)
END
GO
IF (80 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'HomePage'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'HomePage'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [HomePage] varchar(80)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LandName'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LandName'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LandName] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LandName'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'LandName'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [LandName] varchar(40)
END
GO
IF (15 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'RefTo'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'RefTo'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [RefTo] char(15)
END
GO
IF (15 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'RefTo'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'RefTo'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [RefTo] varchar(15)
END
GO
IF (11 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SWIFT_BIC'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SWIFT_BIC'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SWIFT_BIC] char(11)
END
GO
IF (11 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SWIFT_BIC'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'SWIFT_BIC'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [SWIFT_BIC] varchar(11)
END
GO
IF (34 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'IBAN'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'IBAN'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [IBAN] char(34)
END
GO
IF (34 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'IBAN'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'IBAN'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [IBAN] varchar(34)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatenHerk'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatenHerk'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DatenHerk] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatenHerk'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'DatenHerk'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [DatenHerk] varchar(30)
END
GO
IF (10 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EDocType'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EDocType'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [EDocType] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EDocType'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'EDocType'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [EDocType] varchar(10)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoInh'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoInh'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoInh] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoInh'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'KontoInh'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [KontoInh] varchar(40)
END
GO
IF (40 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PeppolAddr'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PeppolAddr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PeppolAddr] char(40)
END
GO
IF (40 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PeppolAddr'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Adressen' and sc.[name] = 'PeppolAddr'))
BEGIN
   ALTER TABLE [dbo].[ut_Adressen] ALTER COLUMN [PeppolAddr] varchar(40)
END
GO

-- create dedicated view
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Adressen')
  DROP VIEW [dbo].[Adressen]
GO
CREATE VIEW [dbo].[Adressen] AS
  SELECT [RecId]
 ,[DESTDEBNR]
 ,[DESTTYP]
 ,[SUCHEN]
 ,[Anrede]
 ,[VorName]
 ,[Name1]
 ,[Name2]
 ,[Branche]
 ,[Strasse]
 ,[Ort]
 ,[Land]
 ,[Plz]
 ,[PsfPlz]
 ,[Psf]
 ,[PlzGrossEm]
 ,[zuHaenden]
 ,[zuHaeAnre]
 ,[BrAnrede]
 ,[BrGruss]
 ,[Telefon1]
 ,[Tel1Kurz]
 ,[Telefon2]
 ,[Tel2Kurz]
 ,[Telefon3]
 ,[Tel3Kurz]
 ,[FaxNummer]
 ,[FaxKurz]
 ,[EMail]
 ,[SpKzJn]
 ,[Selection1]
 ,[Selection2]
 ,[DatumAnlag]
 ,[DatumAende]
 ,[FibuKonto]
 ,[KzDivers]
 ,[KzAdr]
 ,[KzKh]
 ,[Kondition]
 ,[MahnenJN]
 ,[MahnKondit]
 ,[SkontoTole]
 ,[Blz1]
 ,[KontoNr1]
 ,[Blz2]
 ,[KontoNr2]
 ,[Blz3]
 ,[KontoNr3]
 ,[KreditLimi]
 ,[UstId1]
 ,[Dokument]
 ,[Info1]
 ,[Info2]
 ,[Info3]
 ,[Info4]
 ,[LkzImport]
 ,[KzPreisPfl]
 ,[LiefKdNrD]
 ,[LiefKdNrE]
 ,[KostSt]
 ,[AbrGruppe]
 ,[SollStd]
 ,[BaGruppe]
 ,[EkLohn]
 ,[Annr]
 ,[Res4NG2]
 ,[BruttoLohn]
 ,[HomePage]
 ,[LandName]
 ,[RefTo]
 ,[SWIFT_BIC]
 ,[IBAN]
 ,[DatenHerk]
 ,[SyncState]
 ,[EDocType]
 ,[KontoInh]
 ,[PeppolAddr]
  FROM [dbo].[ut_Adressen]
GO


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

-- select with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Adressen')
  DROP PROCEDURE [dbo].[up_Sel_Adressen]
GO
CREATE PROCEDURE [dbo].[up_Sel_Adressen]  @mRI integer
AS
  SELECT
    [DESTDEBNR]
   ,[DESTTYP]
   ,[SUCHEN]
   ,[Anrede]
   ,[VorName]
   ,[Name1]
   ,[Name2]
   ,[Branche]
   ,[Strasse]
   ,[Ort]
   ,[Land]
   ,[Plz]
   ,[PsfPlz]
   ,[Psf]
   ,[PlzGrossEm]
   ,[zuHaenden]
   ,[zuHaeAnre]
   ,[BrAnrede]
   ,[BrGruss]
   ,[Telefon1]
   ,[Tel1Kurz]
   ,[Telefon2]
   ,[Tel2Kurz]
   ,[Telefon3]
   ,[Tel3Kurz]
   ,[FaxNummer]
   ,[FaxKurz]
   ,[EMail]
   ,[SpKzJn]
   ,[Selection1]
   ,[Selection2]
   ,[DatumAnlag]
   ,[DatumAende]
   ,[FibuKonto]
   ,[KzDivers]
   ,[KzAdr]
   ,[KzKh]
   ,[Kondition]
   ,[MahnenJN]
   ,[MahnKondit]
   ,[SkontoTole]
   ,[Blz1]
   ,[KontoNr1]
   ,[Blz2]
   ,[KontoNr2]
   ,[Blz3]
   ,[KontoNr3]
   ,[KreditLimi]
   ,[UstId1]
   ,[Dokument]
   ,[Info1]
   ,[Info2]
   ,[Info3]
   ,[Info4]
   ,[LkzImport]
   ,[KzPreisPfl]
   ,[LiefKdNrD]
   ,[LiefKdNrE]
   ,[KostSt]
   ,[AbrGruppe]
   ,[SollStd]
   ,[BaGruppe]
   ,[EkLohn]
   ,[Annr]
   ,[Res4NG2]
   ,[BruttoLohn]
   ,[HomePage]
   ,[LandName]
   ,[RefTo]
   ,[SWIFT_BIC]
   ,[IBAN]
   ,[DatenHerk]
   ,[SyncState]
   ,[EDocType]
   ,[KontoInh]
   ,[PeppolAddr]
  FROM [dbo].[ut_Adressen] WHERE RecId = @mRI
GO

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

-- insert with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Adressen')
  DROP PROCEDURE [dbo].[up_Append_Adressen]
GO
CREATE PROCEDURE [dbo].[up_Append_Adressen]
   @Param_DESTDEBNR char(15)
  ,@Param_DESTTYP char(2)
  ,@Param_SUCHEN char(40)
  ,@Param_Anrede varchar(40)
  ,@Param_VorName varchar(40)
  ,@Param_Name1 char(40)
  ,@Param_Name2 varchar(40)
  ,@Param_Branche varchar(40)
  ,@Param_Strasse varchar(40)
  ,@Param_Ort char(40)
  ,@Param_Land varchar(6)
  ,@Param_Plz char(10)
  ,@Param_PsfPlz char(10)
  ,@Param_Psf char(15)
  ,@Param_PlzGrossEm char(10)
  ,@Param_zuHaenden varchar(40)
  ,@Param_zuHaeAnre varchar(40)
  ,@Param_BrAnrede varchar(40)
  ,@Param_BrGruss varchar(40)
  ,@Param_Telefon1 varchar(20)
  ,@Param_Tel1Kurz varchar(20)
  ,@Param_Telefon2 varchar(20)
  ,@Param_Tel2Kurz varchar(20)
  ,@Param_Telefon3 varchar(20)
  ,@Param_Tel3Kurz varchar(20)
  ,@Param_FaxNummer varchar(20)
  ,@Param_FaxKurz varchar(20)
  ,@Param_EMail varchar(80)
  ,@Param_SpKzJn tinyint
  ,@Param_Selection1 varchar(15)
  ,@Param_Selection2 varchar(15)
  ,@Param_DatumAnlag datetime
  ,@Param_DatumAende datetime
  ,@Param_FibuKonto char(15)
  ,@Param_KzDivers tinyint
  ,@Param_KzAdr char(1)
  ,@Param_KzKh tinyint
  ,@Param_Kondition integer
  ,@Param_MahnenJN tinyint
  ,@Param_MahnKondit varchar(50)
  ,@Param_SkontoTole varchar(50)
  ,@Param_Blz1 varchar(11)
  ,@Param_KontoNr1 varchar(15)
  ,@Param_Blz2 varchar(11)
  ,@Param_KontoNr2 varchar(15)
  ,@Param_Blz3 varchar(11)
  ,@Param_KontoNr3 varchar(15)
  ,@Param_KreditLimi float
  ,@Param_UstId1 varchar(15)
  ,@Param_Dokument varchar(42)
  ,@Param_Info1 char(20)
  ,@Param_Info2 char(20)
  ,@Param_Info3 char(20)
  ,@Param_Info4 char(20)
  ,@Param_LkzImport char(2)
  ,@Param_KzPreisPfl tinyint
  ,@Param_LiefKdNrD char(20)
  ,@Param_LiefKdNrE char(20)
  ,@Param_KostSt char(20)
  ,@Param_AbrGruppe integer
  ,@Param_SollStd float
  ,@Param_BaGruppe char(2)
  ,@Param_EkLohn float
  ,@Param_Annr char(4)
  ,@Param_Res4NG2 varchar(28)
  ,@Param_BruttoLohn float
  ,@Param_HomePage varchar(80)
  ,@Param_LandName varchar(40)
  ,@Param_RefTo char(15)
  ,@Param_SWIFT_BIC char(11)
  ,@Param_IBAN char(34)
  ,@Param_DatenHerk varchar(30)
  ,@Param_SyncState integer
  ,@Param_EDocType char(10)
  ,@Param_KontoInh varchar(40)
  ,@Param_PeppolAddr varchar(40)
AS
  DECLARE @NeueId integer
  DECLARE @m_CountDown integer = 10
  WHILE @m_CountDown > 0 BEGIN
    BEGIN TRANSACTION
    BEGIN TRY
      SET @NeueId = dbo.itcfunc_NextRecId_Adressen()
      INSERT INTO [dbo].[ut_Adressen] (RecId
        ,[DESTDEBNR]
        ,[DESTTYP]
        ,[SUCHEN]
        ,[Anrede]
        ,[VorName]
        ,[Name1]
        ,[Name2]
        ,[Branche]
        ,[Strasse]
        ,[Ort]
        ,[Land]
        ,[Plz]
        ,[PsfPlz]
        ,[Psf]
        ,[PlzGrossEm]
        ,[zuHaenden]
        ,[zuHaeAnre]
        ,[BrAnrede]
        ,[BrGruss]
        ,[Telefon1]
        ,[Tel1Kurz]
        ,[Telefon2]
        ,[Tel2Kurz]
        ,[Telefon3]
        ,[Tel3Kurz]
        ,[FaxNummer]
        ,[FaxKurz]
        ,[EMail]
        ,[SpKzJn]
        ,[Selection1]
        ,[Selection2]
        ,[DatumAnlag]
        ,[DatumAende]
        ,[FibuKonto]
        ,[KzDivers]
        ,[KzAdr]
        ,[KzKh]
        ,[Kondition]
        ,[MahnenJN]
        ,[MahnKondit]
        ,[SkontoTole]
        ,[Blz1]
        ,[KontoNr1]
        ,[Blz2]
        ,[KontoNr2]
        ,[Blz3]
        ,[KontoNr3]
        ,[KreditLimi]
        ,[UstId1]
        ,[Dokument]
        ,[Info1]
        ,[Info2]
        ,[Info3]
        ,[Info4]
        ,[LkzImport]
        ,[KzPreisPfl]
        ,[LiefKdNrD]
        ,[LiefKdNrE]
        ,[KostSt]
        ,[AbrGruppe]
        ,[SollStd]
        ,[BaGruppe]
        ,[EkLohn]
        ,[Annr]
        ,[Res4NG2]
        ,[BruttoLohn]
        ,[HomePage]
        ,[LandName]
        ,[RefTo]
        ,[SWIFT_BIC]
        ,[IBAN]
        ,[DatenHerk]
        ,[SyncState]
        ,[EDocType]
        ,[KontoInh]
        ,[PeppolAddr]
          ) VALUES (@NeueId
        ,UPPER(RTRIM(@Param_DESTDEBNR))
        ,UPPER(RTRIM(@Param_DESTTYP))
        ,UPPER(RTRIM(@Param_SUCHEN))
        ,RTRIM(@Param_Anrede)
        ,RTRIM(@Param_VorName)
        ,RTRIM(@Param_Name1)
        ,RTRIM(@Param_Name2)
        ,RTRIM(@Param_Branche)
        ,RTRIM(@Param_Strasse)
        ,RTRIM(@Param_Ort)
        ,RTRIM(@Param_Land)
        ,RTRIM(@Param_Plz)
        ,RTRIM(@Param_PsfPlz)
        ,RTRIM(@Param_Psf)
        ,RTRIM(@Param_PlzGrossEm)
        ,RTRIM(@Param_zuHaenden)
        ,RTRIM(@Param_zuHaeAnre)
        ,RTRIM(@Param_BrAnrede)
        ,RTRIM(@Param_BrGruss)
        ,RTRIM(@Param_Telefon1)
        ,RTRIM(@Param_Tel1Kurz)
        ,RTRIM(@Param_Telefon2)
        ,RTRIM(@Param_Tel2Kurz)
        ,RTRIM(@Param_Telefon3)
        ,RTRIM(@Param_Tel3Kurz)
        ,RTRIM(@Param_FaxNummer)
        ,RTRIM(@Param_FaxKurz)
        ,RTRIM(@Param_EMail)
        ,@Param_SpKzJn
        ,RTRIM(@Param_Selection1)
        ,RTRIM(@Param_Selection2)
        ,@Param_DatumAnlag
        ,@Param_DatumAende
        ,RTRIM(@Param_FibuKonto)
        ,@Param_KzDivers
        ,RTRIM(@Param_KzAdr)
        ,@Param_KzKh
        ,@Param_Kondition
        ,@Param_MahnenJN
        ,RTRIM(@Param_MahnKondit)
        ,RTRIM(@Param_SkontoTole)
        ,RTRIM(@Param_Blz1)
        ,RTRIM(@Param_KontoNr1)
        ,RTRIM(@Param_Blz2)
        ,RTRIM(@Param_KontoNr2)
        ,RTRIM(@Param_Blz3)
        ,RTRIM(@Param_KontoNr3)
        ,@Param_KreditLimi
        ,RTRIM(@Param_UstId1)
        ,RTRIM(@Param_Dokument)
        ,UPPER(RTRIM(@Param_Info1))
        ,UPPER(RTRIM(@Param_Info2))
        ,UPPER(RTRIM(@Param_Info3))
        ,UPPER(RTRIM(@Param_Info4))
        ,UPPER(RTRIM(@Param_LkzImport))
        ,@Param_KzPreisPfl
        ,UPPER(RTRIM(@Param_LiefKdNrD))
        ,UPPER(RTRIM(@Param_LiefKdNrE))
        ,UPPER(RTRIM(@Param_KostSt))
        ,@Param_AbrGruppe
        ,@Param_SollStd
        ,UPPER(RTRIM(@Param_BaGruppe))
        ,@Param_EkLohn
        ,UPPER(RTRIM(@Param_Annr))
        ,RTRIM(@Param_Res4NG2)
        ,@Param_BruttoLohn
        ,RTRIM(@Param_HomePage)
        ,RTRIM(@Param_LandName)
        ,UPPER(RTRIM(@Param_RefTo))
        ,UPPER(RTRIM(@Param_SWIFT_BIC))
        ,UPPER(RTRIM(@Param_IBAN))
        ,RTRIM(@Param_DatenHerk)
        ,@Param_SyncState
        ,UPPER(RTRIM(@Param_EDocType))
        ,RTRIM(@Param_KontoInh)
        ,RTRIM(@Param_PeppolAddr)
          )
      COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
      ROLLBACK TRANSACTION
      SET @NeueId = 0
    END CATCH

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

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

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

-- update with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_Adressen')
  DROP PROCEDURE [dbo].[up_Upd_Adressen]
GO
CREATE PROCEDURE [dbo].[up_Upd_Adressen] @mRI integer
  ,@Param_DESTDEBNR char(15)
  ,@Param_DESTTYP char(2)
  ,@Param_SUCHEN char(40)
  ,@Param_Anrede varchar(40)
  ,@Param_VorName varchar(40)
  ,@Param_Name1 char(40)
  ,@Param_Name2 varchar(40)
  ,@Param_Branche varchar(40)
  ,@Param_Strasse varchar(40)
  ,@Param_Ort char(40)
  ,@Param_Land varchar(6)
  ,@Param_Plz char(10)
  ,@Param_PsfPlz char(10)
  ,@Param_Psf char(15)
  ,@Param_PlzGrossEm char(10)
  ,@Param_zuHaenden varchar(40)
  ,@Param_zuHaeAnre varchar(40)
  ,@Param_BrAnrede varchar(40)
  ,@Param_BrGruss varchar(40)
  ,@Param_Telefon1 varchar(20)
  ,@Param_Tel1Kurz varchar(20)
  ,@Param_Telefon2 varchar(20)
  ,@Param_Tel2Kurz varchar(20)
  ,@Param_Telefon3 varchar(20)
  ,@Param_Tel3Kurz varchar(20)
  ,@Param_FaxNummer varchar(20)
  ,@Param_FaxKurz varchar(20)
  ,@Param_EMail varchar(80)
  ,@Param_SpKzJn tinyint
  ,@Param_Selection1 varchar(15)
  ,@Param_Selection2 varchar(15)
  ,@Param_DatumAnlag datetime
  ,@Param_DatumAende datetime
  ,@Param_FibuKonto char(15)
  ,@Param_KzDivers tinyint
  ,@Param_KzAdr char(1)
  ,@Param_KzKh tinyint
  ,@Param_Kondition integer
  ,@Param_MahnenJN tinyint
  ,@Param_MahnKondit varchar(50)
  ,@Param_SkontoTole varchar(50)
  ,@Param_Blz1 varchar(11)
  ,@Param_KontoNr1 varchar(15)
  ,@Param_Blz2 varchar(11)
  ,@Param_KontoNr2 varchar(15)
  ,@Param_Blz3 varchar(11)
  ,@Param_KontoNr3 varchar(15)
  ,@Param_KreditLimi float
  ,@Param_UstId1 varchar(15)
  ,@Param_Dokument varchar(42)
  ,@Param_Info1 char(20)
  ,@Param_Info2 char(20)
  ,@Param_Info3 char(20)
  ,@Param_Info4 char(20)
  ,@Param_LkzImport char(2)
  ,@Param_KzPreisPfl tinyint
  ,@Param_LiefKdNrD char(20)
  ,@Param_LiefKdNrE char(20)
  ,@Param_KostSt char(20)
  ,@Param_AbrGruppe integer
  ,@Param_SollStd float
  ,@Param_BaGruppe char(2)
  ,@Param_EkLohn float
  ,@Param_Annr char(4)
  ,@Param_Res4NG2 varchar(28)
  ,@Param_BruttoLohn float
  ,@Param_HomePage varchar(80)
  ,@Param_LandName varchar(40)
  ,@Param_RefTo char(15)
  ,@Param_SWIFT_BIC char(11)
  ,@Param_IBAN char(34)
  ,@Param_DatenHerk varchar(30)
  ,@Param_SyncState integer
  ,@Param_EDocType char(10)
  ,@Param_KontoInh varchar(40)
  ,@Param_PeppolAddr varchar(40)
AS
  UPDATE [dbo].[ut_Adressen] SET
    [DESTDEBNR] = UPPER(RTRIM(@Param_DESTDEBNR))
   ,[DESTTYP] = UPPER(RTRIM(@Param_DESTTYP))
   ,[SUCHEN] = UPPER(RTRIM(@Param_SUCHEN))
   ,[Anrede] = RTRIM(@Param_Anrede)
   ,[VorName] = RTRIM(@Param_VorName)
   ,[Name1] = RTRIM(@Param_Name1)
   ,[Name2] = RTRIM(@Param_Name2)
   ,[Branche] = RTRIM(@Param_Branche)
   ,[Strasse] = RTRIM(@Param_Strasse)
   ,[Ort] = RTRIM(@Param_Ort)
   ,[Land] = RTRIM(@Param_Land)
   ,[Plz] = RTRIM(@Param_Plz)
   ,[PsfPlz] = RTRIM(@Param_PsfPlz)
   ,[Psf] = RTRIM(@Param_Psf)
   ,[PlzGrossEm] = RTRIM(@Param_PlzGrossEm)
   ,[zuHaenden] = RTRIM(@Param_zuHaenden)
   ,[zuHaeAnre] = RTRIM(@Param_zuHaeAnre)
   ,[BrAnrede] = RTRIM(@Param_BrAnrede)
   ,[BrGruss] = RTRIM(@Param_BrGruss)
   ,[Telefon1] = RTRIM(@Param_Telefon1)
   ,[Tel1Kurz] = RTRIM(@Param_Tel1Kurz)
   ,[Telefon2] = RTRIM(@Param_Telefon2)
   ,[Tel2Kurz] = RTRIM(@Param_Tel2Kurz)
   ,[Telefon3] = RTRIM(@Param_Telefon3)
   ,[Tel3Kurz] = RTRIM(@Param_Tel3Kurz)
   ,[FaxNummer] = RTRIM(@Param_FaxNummer)
   ,[FaxKurz] = RTRIM(@Param_FaxKurz)
   ,[EMail] = RTRIM(@Param_EMail)
   ,[SpKzJn] = @Param_SpKzJn
   ,[Selection1] = RTRIM(@Param_Selection1)
   ,[Selection2] = RTRIM(@Param_Selection2)
   ,[DatumAnlag] = @Param_DatumAnlag
   ,[DatumAende] = @Param_DatumAende
   ,[FibuKonto] = RTRIM(@Param_FibuKonto)
   ,[KzDivers] = @Param_KzDivers
   ,[KzAdr] = RTRIM(@Param_KzAdr)
   ,[KzKh] = @Param_KzKh
   ,[Kondition] = @Param_Kondition
   ,[MahnenJN] = @Param_MahnenJN
   ,[MahnKondit] = RTRIM(@Param_MahnKondit)
   ,[SkontoTole] = RTRIM(@Param_SkontoTole)
   ,[Blz1] = RTRIM(@Param_Blz1)
   ,[KontoNr1] = RTRIM(@Param_KontoNr1)
   ,[Blz2] = RTRIM(@Param_Blz2)
   ,[KontoNr2] = RTRIM(@Param_KontoNr2)
   ,[Blz3] = RTRIM(@Param_Blz3)
   ,[KontoNr3] = RTRIM(@Param_KontoNr3)
   ,[KreditLimi] = @Param_KreditLimi
   ,[UstId1] = RTRIM(@Param_UstId1)
   ,[Dokument] = RTRIM(@Param_Dokument)
   ,[Info1] = UPPER(RTRIM(@Param_Info1))
   ,[Info2] = UPPER(RTRIM(@Param_Info2))
   ,[Info3] = UPPER(RTRIM(@Param_Info3))
   ,[Info4] = UPPER(RTRIM(@Param_Info4))
   ,[LkzImport] = UPPER(RTRIM(@Param_LkzImport))
   ,[KzPreisPfl] = @Param_KzPreisPfl
   ,[LiefKdNrD] = UPPER(RTRIM(@Param_LiefKdNrD))
   ,[LiefKdNrE] = UPPER(RTRIM(@Param_LiefKdNrE))
   ,[KostSt] = UPPER(RTRIM(@Param_KostSt))
   ,[AbrGruppe] = @Param_AbrGruppe
   ,[SollStd] = @Param_SollStd
   ,[BaGruppe] = UPPER(RTRIM(@Param_BaGruppe))
   ,[EkLohn] = @Param_EkLohn
   ,[Annr] = UPPER(RTRIM(@Param_Annr))
   ,[Res4NG2] = RTRIM(@Param_Res4NG2)
   ,[BruttoLohn] = @Param_BruttoLohn
   ,[HomePage] = RTRIM(@Param_HomePage)
   ,[LandName] = RTRIM(@Param_LandName)
   ,[RefTo] = UPPER(RTRIM(@Param_RefTo))
   ,[SWIFT_BIC] = UPPER(RTRIM(@Param_SWIFT_BIC))
   ,[IBAN] = UPPER(RTRIM(@Param_IBAN))
   ,[DatenHerk] = RTRIM(@Param_DatenHerk)
   ,[SyncState] = @Param_SyncState
   ,[EDocType] = UPPER(RTRIM(@Param_EDocType))
   ,[KontoInh] = RTRIM(@Param_KontoInh)
   ,[PeppolAddr] = RTRIM(@Param_PeppolAddr)
  WHERE RecId = @mRI
GO

-- update with modern clients
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd2_Adressen')
  DROP PROCEDURE [dbo].[up_Upd2_Adressen]
GO
CREATE PROCEDURE [dbo].[up_Upd2_Adressen] @Param_RecId varchar(20)
  ,@Param_DESTDEBNR varchar(15)
  ,@Param_DESTTYP varchar(2)
  ,@Param_SUCHEN varchar(40)
  ,@Param_Anrede varchar(40)
  ,@Param_VorName varchar(40)
  ,@Param_Name1 varchar(40)
  ,@Param_Name2 varchar(40)
  ,@Param_Branche varchar(40)
  ,@Param_Strasse varchar(40)
  ,@Param_Ort varchar(40)
  ,@Param_Land varchar(6)
  ,@Param_Plz varchar(10)
  ,@Param_PsfPlz varchar(10)
  ,@Param_Psf varchar(15)
  ,@Param_PlzGrossEm varchar(10)
  ,@Param_zuHaenden varchar(40)
  ,@Param_zuHaeAnre varchar(40)
  ,@Param_BrAnrede varchar(40)
  ,@Param_BrGruss varchar(40)
  ,@Param_Telefon1 varchar(20)
  ,@Param_Tel1Kurz varchar(20)
  ,@Param_Telefon2 varchar(20)
  ,@Param_Tel2Kurz varchar(20)
  ,@Param_Telefon3 varchar(20)
  ,@Param_Tel3Kurz varchar(20)
  ,@Param_FaxNummer varchar(20)
  ,@Param_FaxKurz varchar(20)
  ,@Param_EMail varchar(80)
  ,@Param_SpKzJn varchar(1)
  ,@Param_Selection1 varchar(15)
  ,@Param_Selection2 varchar(15)
  ,@Param_DatumAnlag varchar(10)
  ,@Param_DatumAende varchar(10)
  ,@Param_FibuKonto varchar(15)
  ,@Param_KzDivers varchar(1)
  ,@Param_KzAdr varchar(1)
  ,@Param_KzKh varchar(1)
  ,@Param_Kondition varchar(5)
  ,@Param_MahnenJN varchar(1)
  ,@Param_MahnKondit varchar(50)
  ,@Param_SkontoTole varchar(50)
  ,@Param_Blz1 varchar(11)
  ,@Param_KontoNr1 varchar(15)
  ,@Param_Blz2 varchar(11)
  ,@Param_KontoNr2 varchar(15)
  ,@Param_Blz3 varchar(11)
  ,@Param_KontoNr3 varchar(15)
  ,@Param_KreditLimi varchar(9)
  ,@Param_UstId1 varchar(15)
  ,@Param_Dokument varchar(42)
  ,@Param_Info1 varchar(20)
  ,@Param_Info2 varchar(20)
  ,@Param_Info3 varchar(20)
  ,@Param_Info4 varchar(20)
  ,@Param_LkzImport varchar(2)
  ,@Param_KzPreisPfl varchar(1)
  ,@Param_LiefKdNrD varchar(20)
  ,@Param_LiefKdNrE varchar(20)
  ,@Param_KostSt varchar(20)
  ,@Param_AbrGruppe varchar(1)
  ,@Param_SollStd varchar(6)
  ,@Param_BaGruppe varchar(2)
  ,@Param_EkLohn varchar(8)
  ,@Param_Annr varchar(4)
  ,@Param_Res4NG2 varchar(28)
  ,@Param_BruttoLohn varchar(8)
  ,@Param_HomePage varchar(80)
  ,@Param_LandName varchar(40)
  ,@Param_RefTo varchar(15)
  ,@Param_SWIFT_BIC varchar(11)
  ,@Param_IBAN varchar(34)
  ,@Param_DatenHerk varchar(30)
  ,@Param_SyncState varchar(1)
  ,@Param_EDocType varchar(10)
  ,@Param_KontoInh varchar(40)
  ,@Param_PeppolAddr varchar(40)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)
  UPDATE [dbo].[ut_Adressen] SET
    [DESTDEBNR] = UPPER(RTRIM(@Param_DESTDEBNR))
   ,[DESTTYP] = UPPER(RTRIM(@Param_DESTTYP))
   ,[SUCHEN] = UPPER(RTRIM(@Param_SUCHEN))
   ,[Anrede] = RTRIM(@Param_Anrede)
   ,[VorName] = RTRIM(@Param_VorName)
   ,[Name1] = RTRIM(@Param_Name1)
   ,[Name2] = RTRIM(@Param_Name2)
   ,[Branche] = RTRIM(@Param_Branche)
   ,[Strasse] = RTRIM(@Param_Strasse)
   ,[Ort] = RTRIM(@Param_Ort)
   ,[Land] = RTRIM(@Param_Land)
   ,[Plz] = RTRIM(@Param_Plz)
   ,[PsfPlz] = RTRIM(@Param_PsfPlz)
   ,[Psf] = RTRIM(@Param_Psf)
   ,[PlzGrossEm] = RTRIM(@Param_PlzGrossEm)
   ,[zuHaenden] = RTRIM(@Param_zuHaenden)
   ,[zuHaeAnre] = RTRIM(@Param_zuHaeAnre)
   ,[BrAnrede] = RTRIM(@Param_BrAnrede)
   ,[BrGruss] = RTRIM(@Param_BrGruss)
   ,[Telefon1] = RTRIM(@Param_Telefon1)
   ,[Tel1Kurz] = RTRIM(@Param_Tel1Kurz)
   ,[Telefon2] = RTRIM(@Param_Telefon2)
   ,[Tel2Kurz] = RTRIM(@Param_Tel2Kurz)
   ,[Telefon3] = RTRIM(@Param_Telefon3)
   ,[Tel3Kurz] = RTRIM(@Param_Tel3Kurz)
   ,[FaxNummer] = RTRIM(@Param_FaxNummer)
   ,[FaxKurz] = RTRIM(@Param_FaxKurz)
   ,[EMail] = RTRIM(@Param_EMail)
   ,[SpKzJn] = dbo.itcfunc_integer(@Param_SpKzJn)
   ,[Selection1] = RTRIM(@Param_Selection1)
   ,[Selection2] = RTRIM(@Param_Selection2)
   ,[DatumAnlag] = dbo.itcfunc_datetime(@Param_DatumAnlag)
   ,[DatumAende] = dbo.itcfunc_datetime(@Param_DatumAende)
   ,[FibuKonto] = RTRIM(@Param_FibuKonto)
   ,[KzDivers] = dbo.itcfunc_integer(@Param_KzDivers)
   ,[KzAdr] = RTRIM(@Param_KzAdr)
   ,[KzKh] = dbo.itcfunc_integer(@Param_KzKh)
   ,[Kondition] = dbo.itcfunc_integer(@Param_Kondition)
   ,[MahnenJN] = dbo.itcfunc_integer(@Param_MahnenJN)
   ,[MahnKondit] = RTRIM(@Param_MahnKondit)
   ,[SkontoTole] = RTRIM(@Param_SkontoTole)
   ,[Blz1] = RTRIM(@Param_Blz1)
   ,[KontoNr1] = RTRIM(@Param_KontoNr1)
   ,[Blz2] = RTRIM(@Param_Blz2)
   ,[KontoNr2] = RTRIM(@Param_KontoNr2)
   ,[Blz3] = RTRIM(@Param_Blz3)
   ,[KontoNr3] = RTRIM(@Param_KontoNr3)
   ,[KreditLimi] = dbo.itcfunc_float(@Param_KreditLimi)
   ,[UstId1] = RTRIM(@Param_UstId1)
   ,[Dokument] = RTRIM(@Param_Dokument)
   ,[Info1] = UPPER(RTRIM(@Param_Info1))
   ,[Info2] = UPPER(RTRIM(@Param_Info2))
   ,[Info3] = UPPER(RTRIM(@Param_Info3))
   ,[Info4] = UPPER(RTRIM(@Param_Info4))
   ,[LkzImport] = UPPER(RTRIM(@Param_LkzImport))
   ,[KzPreisPfl] = dbo.itcfunc_integer(@Param_KzPreisPfl)
   ,[LiefKdNrD] = UPPER(RTRIM(@Param_LiefKdNrD))
   ,[LiefKdNrE] = UPPER(RTRIM(@Param_LiefKdNrE))
   ,[KostSt] = UPPER(RTRIM(@Param_KostSt))
   ,[AbrGruppe] = dbo.itcfunc_integer(@Param_AbrGruppe)
   ,[SollStd] = dbo.itcfunc_float(@Param_SollStd)
   ,[BaGruppe] = UPPER(RTRIM(@Param_BaGruppe))
   ,[EkLohn] = dbo.itcfunc_float(@Param_EkLohn)
   ,[Annr] = UPPER(RTRIM(@Param_Annr))
   ,[Res4NG2] = RTRIM(@Param_Res4NG2)
   ,[BruttoLohn] = dbo.itcfunc_float(@Param_BruttoLohn)
   ,[HomePage] = RTRIM(@Param_HomePage)
   ,[LandName] = RTRIM(@Param_LandName)
   ,[RefTo] = UPPER(RTRIM(@Param_RefTo))
   ,[SWIFT_BIC] = UPPER(RTRIM(@Param_SWIFT_BIC))
   ,[IBAN] = UPPER(RTRIM(@Param_IBAN))
   ,[DatenHerk] = RTRIM(@Param_DatenHerk)
   ,[SyncState] = dbo.itcfunc_integer(@Param_SyncState)
   ,[EDocType] = UPPER(RTRIM(@Param_EDocType))
   ,[KontoInh] = RTRIM(@Param_KontoInh)
   ,[PeppolAddr] = RTRIM(@Param_PeppolAddr)
  WHERE RecId = @mRI

  EXECUTE [dbo].[up_Sel2_Adressen] @mRI
GO

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

-- text index
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_Adressen')
  DROP PROCEDURE [dbo].[up_TrSel_Adressen]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Adressen]
AS
  SELECT RecId,
    LTRIM(RTRIM([DESTDEBNR]))
   +LTRIM(RTRIM([DESTTYP]))
   +LTRIM(RTRIM([SUCHEN]))
   +LTRIM(RTRIM([Anrede]))
   +LTRIM(RTRIM([VorName]))
   +LTRIM(RTRIM([Name1]))
   +LTRIM(RTRIM([Name2]))
   +LTRIM(RTRIM([Branche]))
   +LTRIM(RTRIM([Strasse]))
   +LTRIM(RTRIM([Ort]))
   +LTRIM(RTRIM([Land]))
   +LTRIM(RTRIM([Plz]))
   +LTRIM(RTRIM([PsfPlz]))
   +LTRIM(RTRIM([Psf]))
   +LTRIM(RTRIM([PlzGrossEm]))
   +LTRIM(RTRIM([zuHaenden]))
   +LTRIM(RTRIM([zuHaeAnre]))
   +LTRIM(RTRIM([BrAnrede]))
   +LTRIM(RTRIM([BrGruss]))
   +LTRIM(RTRIM([Telefon1]))
   +LTRIM(RTRIM([Tel1Kurz]))
   +LTRIM(RTRIM([Telefon2]))
   +LTRIM(RTRIM([Tel2Kurz]))
   +LTRIM(RTRIM([Telefon3]))
   +LTRIM(RTRIM([Tel3Kurz]))
   +LTRIM(RTRIM([FaxNummer]))
   +LTRIM(RTRIM([FaxKurz]))
   +LTRIM(RTRIM([EMail]))
   +LTRIM(RTRIM([Selection1]))
   +LTRIM(RTRIM([Selection2]))
   +LTRIM(RTRIM([FibuKonto]))
   +LTRIM(RTRIM([KzAdr]))
   +LTRIM(RTRIM([MahnKondit]))
   +LTRIM(RTRIM([SkontoTole]))
   +LTRIM(RTRIM([Blz1]))
   +LTRIM(RTRIM([KontoNr1]))
   +LTRIM(RTRIM([Blz2]))
   +LTRIM(RTRIM([KontoNr2]))
   +LTRIM(RTRIM([Blz3]))
   +LTRIM(RTRIM([KontoNr3]))
   +LTRIM(RTRIM([UstId1]))
   +LTRIM(RTRIM([Dokument]))
   +LTRIM(RTRIM([Info1]))
   +LTRIM(RTRIM([Info2]))
   +LTRIM(RTRIM([Info3]))
   +LTRIM(RTRIM([Info4]))
   +LTRIM(RTRIM([LkzImport]))
   +LTRIM(RTRIM([LiefKdNrD]))
   +LTRIM(RTRIM([LiefKdNrE]))
   +LTRIM(RTRIM([KostSt]))
   +LTRIM(RTRIM([BaGruppe]))
   +LTRIM(RTRIM([Annr]))
   +LTRIM(RTRIM([Res4NG2]))
   +LTRIM(RTRIM([HomePage]))
   +LTRIM(RTRIM([LandName]))
   +LTRIM(RTRIM([RefTo]))
   +LTRIM(RTRIM([SWIFT_BIC]))
   +LTRIM(RTRIM([IBAN]))
   +LTRIM(RTRIM([DatenHerk]))
   +LTRIM(RTRIM([EDocType]))
   +LTRIM(RTRIM([KontoInh]))
   +LTRIM(RTRIM([PeppolAddr]))
  AS Data FROM [dbo].[ut_Adressen] WHERE RecId > 0 ORDER BY RecId
GO

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key0')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key0]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key0] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) ORDER BY DESTDEBNR,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key0] AS EXECUTE [dbo].[up_First_Adressen_Key0]')
GO

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key0')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key0]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key0] @oldRecId integer AS
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE (DESTDEBNR > @oldDESTDEBNR)
    ORDER BY DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key0')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key0]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key0] @oldRecId integer AS
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE (DESTDEBNR < @oldDESTDEBNR)
    ORDER BY DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key0')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key0]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key0] @xKey char(250), @xLen integer AS
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY DESTDEBNR,RecId
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR >= @mDESTDEBNR AND SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY DESTDEBNR,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key0')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key0]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key0] @xKey char(250), @xLen integer AS
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY DESTDEBNR desc,RecId desc
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY DESTDEBNR desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key1] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE (DESTTYP < '10') ORDER BY SUCHEN,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key1')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key1] AS EXECUTE [dbo].[up_First_Adressen_Key1]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key1] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE (DESTTYP < '10') ORDER BY SUCHEN desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key1')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key1] AS EXECUTE [dbo].[up_Last_Adressen_Key1]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key1] @oldRecId integer AS
  DECLARE @oldSUCHEN char(40)
  SELECT @oldSUCHEN = SUCHEN FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE ((SUCHEN = @oldSUCHEN) AND (RecId > @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY SUCHEN,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE ((SUCHEN > @oldSUCHEN)) AND ((DESTTYP < '10'))
    ORDER BY SUCHEN,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key1] @oldRecId integer AS
  DECLARE @oldSUCHEN char(40)
  SELECT @oldSUCHEN = SUCHEN FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE ((SUCHEN = @oldSUCHEN) AND (RecId < @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY SUCHEN desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE ((SUCHEN < @oldSUCHEN)) AND ((DESTTYP < '10'))
    ORDER BY SUCHEN desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key1] @xKey char(250), @xLen integer AS
  DECLARE @mSUCHEN char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN = @mSUCHEN
      AND ((DESTTYP < '10'))
      ORDER BY SUCHEN,RecId
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN >= @mSUCHEN AND SUBSTRING(SUCHEN,1,LEN(@mSUCHEN)) = @mSUCHEN
      AND ((DESTTYP < '10'))
      ORDER BY SUCHEN,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key1')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key1]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key1] @xKey char(250), @xLen integer AS
  DECLARE @mSUCHEN char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN = @mSUCHEN
      AND ((DESTTYP < '10'))
      ORDER BY SUCHEN desc,RecId desc
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUBSTRING(SUCHEN,1,LEN(@mSUCHEN)) = @mSUCHEN
      AND ((DESTTYP < '10'))
      ORDER BY SUCHEN desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key2] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE (DESTTYP < '10') ORDER BY Name1,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key2')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key2] AS EXECUTE [dbo].[up_First_Adressen_Key2]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key2] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE (DESTTYP < '10') ORDER BY Name1 desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key2')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key2] AS EXECUTE [dbo].[up_Last_Adressen_Key2]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key2] @oldRecId integer AS
  DECLARE @oldName1 char(40)
  SELECT @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE ((Name1 = @oldName1) AND (RecId > @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE ((Name1 > @oldName1)) AND ((DESTTYP < '10'))
    ORDER BY Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key2] @oldRecId integer AS
  DECLARE @oldName1 char(40)
  SELECT @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE ((Name1 = @oldName1) AND (RecId < @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE ((Name1 < @oldName1)) AND ((DESTTYP < '10'))
    ORDER BY Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key2] @xKey char(250), @xLen integer AS
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 = @mName1
      AND ((DESTTYP < '10'))
      ORDER BY Name1,RecId
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 >= @mName1 AND SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      AND ((DESTTYP < '10'))
      ORDER BY Name1,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key2')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key2]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key2] @xKey char(250), @xLen integer AS
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 = @mName1
      AND ((DESTTYP < '10'))
      ORDER BY Name1 desc,RecId desc
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      AND ((DESTTYP < '10'))
      ORDER BY Name1 desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key3] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE (DESTTYP < '10') ORDER BY Plz,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key3')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key3] AS EXECUTE [dbo].[up_First_Adressen_Key3]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key3] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE (DESTTYP < '10') ORDER BY Plz desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key3')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key3] AS EXECUTE [dbo].[up_Last_Adressen_Key3]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key3] @oldRecId integer AS
  DECLARE @oldPlz char(10)
  SELECT @oldPlz = Plz FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3)
    WHERE ((Plz = @oldPlz) AND (RecId > @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Plz,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3)
    WHERE ((Plz > @oldPlz)) AND ((DESTTYP < '10'))
    ORDER BY Plz,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key3] @oldRecId integer AS
  DECLARE @oldPlz char(10)
  SELECT @oldPlz = Plz FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3)
    WHERE ((Plz = @oldPlz) AND (RecId < @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Plz desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3)
    WHERE ((Plz < @oldPlz)) AND ((DESTTYP < '10'))
    ORDER BY Plz desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key3] @xKey char(250), @xLen integer AS
  DECLARE @mPlz char(10) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,10)

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

  IF @xLen = 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE 
      Plz = @mPlz
      AND ((DESTTYP < '10'))
      ORDER BY Plz,RecId
    RETURN
  END

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

  IF @xLen < 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE 
      Plz >= @mPlz AND SUBSTRING(Plz,1,LEN(@mPlz)) = @mPlz
      AND ((DESTTYP < '10'))
      ORDER BY Plz,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key3')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key3]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key3] @xKey char(250), @xLen integer AS
  DECLARE @mPlz char(10) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,10)

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

  IF @xLen = 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE 
      Plz = @mPlz
      AND ((DESTTYP < '10'))
      ORDER BY Plz desc,RecId desc
    RETURN
  END

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

  IF @xLen < 10 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key3) WHERE 
      SUBSTRING(Plz,1,LEN(@mPlz)) = @mPlz
      AND ((DESTTYP < '10'))
      ORDER BY Plz desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key4] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE (DESTTYP < '10') ORDER BY Ort,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key4')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key4] AS EXECUTE [dbo].[up_First_Adressen_Key4]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key4] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE (DESTTYP < '10') ORDER BY Ort desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key4')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key4] AS EXECUTE [dbo].[up_Last_Adressen_Key4]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key4] @oldRecId integer AS
  DECLARE @oldOrt char(40)
  SELECT @oldOrt = Ort FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4)
    WHERE ((Ort = @oldOrt) AND (RecId > @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Ort,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4)
    WHERE ((Ort > @oldOrt)) AND ((DESTTYP < '10'))
    ORDER BY Ort,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key4] @oldRecId integer AS
  DECLARE @oldOrt char(40)
  SELECT @oldOrt = Ort FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4)
    WHERE ((Ort = @oldOrt) AND (RecId < @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY Ort desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4)
    WHERE ((Ort < @oldOrt)) AND ((DESTTYP < '10'))
    ORDER BY Ort desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key4] @xKey char(250), @xLen integer AS
  DECLARE @mOrt char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE 
      Ort = @mOrt
      AND ((DESTTYP < '10'))
      ORDER BY Ort,RecId
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE 
      Ort >= @mOrt AND SUBSTRING(Ort,1,LEN(@mOrt)) = @mOrt
      AND ((DESTTYP < '10'))
      ORDER BY Ort,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key4')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key4]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key4] @xKey char(250), @xLen integer AS
  DECLARE @mOrt char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE 
      Ort = @mOrt
      AND ((DESTTYP < '10'))
      ORDER BY Ort desc,RecId desc
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key4) WHERE 
      SUBSTRING(Ort,1,LEN(@mOrt)) = @mOrt
      AND ((DESTTYP < '10'))
      ORDER BY Ort desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key5] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) ORDER BY DESTTYP,LkzImport,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key5')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key5] AS EXECUTE [dbo].[up_First_Adressen_Key5]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key5] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) ORDER BY DESTTYP desc,LkzImport desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key5')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key5] AS EXECUTE [dbo].[up_Last_Adressen_Key5]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key5] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldLkzImport char(2)
  SELECT @oldDESTTYP = DESTTYP, @oldLkzImport = LkzImport FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP = @oldDESTTYP) AND (LkzImport = @oldLkzImport) AND (RecId > @oldRecId)
    ORDER BY DESTTYP,LkzImport,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP = @oldDESTTYP) AND (LkzImport > @oldLkzImport)
    ORDER BY DESTTYP,LkzImport,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP > @oldDESTTYP)
    ORDER BY DESTTYP,LkzImport,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key5] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldLkzImport char(2)
  SELECT @oldDESTTYP = DESTTYP, @oldLkzImport = LkzImport FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP = @oldDESTTYP) AND (LkzImport = @oldLkzImport) AND (RecId < @oldRecId)
    ORDER BY DESTTYP desc,LkzImport desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP = @oldDESTTYP) AND (LkzImport < @oldLkzImport)
    ORDER BY DESTTYP desc,LkzImport desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5)
    WHERE (DESTTYP < @oldDESTTYP)
    ORDER BY DESTTYP desc,LkzImport desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key5] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mLkzImport char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,2)

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

  IF @xLen = 4 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP AND 
      LkzImport = @mLkzImport
      ORDER BY DESTTYP,LkzImport,RecId
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP,LkzImport,RecId
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP,LkzImport,RecId
    RETURN
  END

  IF @xLen < 4 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP AND 
      LkzImport >= @mLkzImport AND SUBSTRING(LkzImport,1,LEN(@mLkzImport)) = @mLkzImport
      ORDER BY DESTTYP,LkzImport,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key5')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key5]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key5] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mLkzImport char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,2)

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

  IF @xLen = 4 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP AND 
      LkzImport = @mLkzImport
      ORDER BY DESTTYP desc,LkzImport desc,RecId desc
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP desc,LkzImport desc,RecId desc
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP desc,LkzImport desc,RecId desc
    RETURN
  END

  IF @xLen < 4 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key5) WHERE 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(LkzImport,1,LEN(@mLkzImport)) = @mLkzImport
      ORDER BY DESTTYP desc,LkzImport desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key6] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) ORDER BY DESTTYP,Annr,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key6')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key6] AS EXECUTE [dbo].[up_First_Adressen_Key6]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key6] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) ORDER BY DESTTYP desc,Annr desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key6')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key6] AS EXECUTE [dbo].[up_Last_Adressen_Key6]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key6] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldAnnr char(4)
  SELECT @oldDESTTYP = DESTTYP, @oldAnnr = Annr FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP = @oldDESTTYP) AND (Annr = @oldAnnr) AND (RecId > @oldRecId)
    ORDER BY DESTTYP,Annr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP = @oldDESTTYP) AND (Annr > @oldAnnr)
    ORDER BY DESTTYP,Annr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP > @oldDESTTYP)
    ORDER BY DESTTYP,Annr,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key6] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldAnnr char(4)
  SELECT @oldDESTTYP = DESTTYP, @oldAnnr = Annr FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP = @oldDESTTYP) AND (Annr = @oldAnnr) AND (RecId < @oldRecId)
    ORDER BY DESTTYP desc,Annr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP = @oldDESTTYP) AND (Annr < @oldAnnr)
    ORDER BY DESTTYP desc,Annr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6)
    WHERE (DESTTYP < @oldDESTTYP)
    ORDER BY DESTTYP desc,Annr desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key6] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mAnnr char(4) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,4)

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

  IF @xLen = 6 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP AND 
      Annr = @mAnnr
      ORDER BY DESTTYP,Annr,RecId
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP,Annr,RecId
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP,Annr,RecId
    RETURN
  END

  IF @xLen < 6 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP AND 
      Annr >= @mAnnr AND SUBSTRING(Annr,1,LEN(@mAnnr)) = @mAnnr
      ORDER BY DESTTYP,Annr,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key6')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key6]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key6] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mAnnr char(4) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,4)

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

  IF @xLen = 6 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP AND 
      Annr = @mAnnr
      ORDER BY DESTTYP desc,Annr desc,RecId desc
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP desc,Annr desc,RecId desc
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP desc,Annr desc,RecId desc
    RETURN
  END

  IF @xLen < 6 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key6) WHERE 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(Annr,1,LEN(@mAnnr)) = @mAnnr
      ORDER BY DESTTYP desc,Annr desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key7] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) ORDER BY DESTTYP,Name1,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key7')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key7] AS EXECUTE [dbo].[up_First_Adressen_Key7]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key7] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) ORDER BY DESTTYP desc,Name1 desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key7')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key7] AS EXECUTE [dbo].[up_Last_Adressen_Key7]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key7] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldName1 char(40)
  SELECT @oldDESTTYP = DESTTYP, @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP = @oldDESTTYP) AND (Name1 = @oldName1) AND (RecId > @oldRecId)
    ORDER BY DESTTYP,Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP = @oldDESTTYP) AND (Name1 > @oldName1)
    ORDER BY DESTTYP,Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP > @oldDESTTYP)
    ORDER BY DESTTYP,Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key7] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldName1 char(40)
  SELECT @oldDESTTYP = DESTTYP, @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP = @oldDESTTYP) AND (Name1 = @oldName1) AND (RecId < @oldRecId)
    ORDER BY DESTTYP desc,Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP = @oldDESTTYP) AND (Name1 < @oldName1)
    ORDER BY DESTTYP desc,Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7)
    WHERE (DESTTYP < @oldDESTTYP)
    ORDER BY DESTTYP desc,Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key7] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,40)

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

  IF @xLen = 42 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP AND 
      Name1 = @mName1
      ORDER BY DESTTYP,Name1,RecId
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP,Name1,RecId
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP,Name1,RecId
    RETURN
  END

  IF @xLen < 42 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP AND 
      Name1 >= @mName1 AND SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      ORDER BY DESTTYP,Name1,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key7')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key7]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key7] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,40)

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

  IF @xLen = 42 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP AND 
      Name1 = @mName1
      ORDER BY DESTTYP desc,Name1 desc,RecId desc
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP desc,Name1 desc,RecId desc
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP desc,Name1 desc,RecId desc
    RETURN
  END

  IF @xLen < 42 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key7) WHERE 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      ORDER BY DESTTYP desc,Name1 desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key8] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) ORDER BY FibuKonto,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key8')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key8] AS EXECUTE [dbo].[up_First_Adressen_Key8]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key8] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) ORDER BY FibuKonto desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key8')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key8] AS EXECUTE [dbo].[up_Last_Adressen_Key8]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key8] @oldRecId integer AS
  DECLARE @oldFibuKonto char(15)
  SELECT @oldFibuKonto = FibuKonto FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8)
    WHERE (FibuKonto = @oldFibuKonto) AND (RecId > @oldRecId)
    ORDER BY FibuKonto,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8)
    WHERE (FibuKonto > @oldFibuKonto)
    ORDER BY FibuKonto,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key8] @oldRecId integer AS
  DECLARE @oldFibuKonto char(15)
  SELECT @oldFibuKonto = FibuKonto FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8)
    WHERE (FibuKonto = @oldFibuKonto) AND (RecId < @oldRecId)
    ORDER BY FibuKonto desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8)
    WHERE (FibuKonto < @oldFibuKonto)
    ORDER BY FibuKonto desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key8] @xKey char(250), @xLen integer AS
  DECLARE @mFibuKonto char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) WHERE 
      FibuKonto = @mFibuKonto
      ORDER BY FibuKonto,RecId
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) WHERE 
      FibuKonto >= @mFibuKonto AND SUBSTRING(FibuKonto,1,LEN(@mFibuKonto)) = @mFibuKonto
      ORDER BY FibuKonto,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key8')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key8]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key8] @xKey char(250), @xLen integer AS
  DECLARE @mFibuKonto char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) WHERE 
      FibuKonto = @mFibuKonto
      ORDER BY FibuKonto desc,RecId desc
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key8) WHERE 
      SUBSTRING(FibuKonto,1,LEN(@mFibuKonto)) = @mFibuKonto
      ORDER BY FibuKonto desc,RecId desc
    RETURN
  END

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


-- logical key  ORDER BY DESTTYP,EMail,RecId
IF 0 < (select count(*) from sysindexes si inner join sysobjects so on so.[xtype] = 'U' and so.[name] = 'ut_Adressen' and so.[id] = si.[id] and si.[name] = 'Ik_Key9')
  DROP INDEX [Ik_Key9] ON [dbo].[ut_Adressen]
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_First_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_Key9] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  ORDER BY DESTTYP,EMail,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_Key9')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_Key9] AS EXECUTE [dbo].[up_First_Adressen_Key9]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_Last_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_Key9] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  ORDER BY DESTTYP desc,EMail desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_Key9')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_Key9] AS EXECUTE [dbo].[up_Last_Adressen_Key9]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_Next_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_Key9] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldEMail varchar(80)
  SELECT @oldDESTTYP = DESTTYP, @oldEMail = EMail FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP = @oldDESTTYP) AND (EMail = @oldEMail) AND (RecId > @oldRecId)
    ORDER BY DESTTYP,EMail,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP = @oldDESTTYP) AND (EMail > @oldEMail)
    ORDER BY DESTTYP,EMail,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP > @oldDESTTYP)
    ORDER BY DESTTYP,EMail,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_Key9] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldEMail varchar(80)
  SELECT @oldDESTTYP = DESTTYP, @oldEMail = EMail FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP = @oldDESTTYP) AND (EMail = @oldEMail) AND (RecId < @oldRecId)
    ORDER BY DESTTYP desc,EMail desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP = @oldDESTTYP) AND (EMail < @oldEMail)
    ORDER BY DESTTYP desc,EMail desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] 
    WHERE (DESTTYP < @oldDESTTYP)
    ORDER BY DESTTYP desc,EMail desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_Key9] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mEMail varchar(80) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,80)

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

  IF @xLen = 82 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP AND 
      EMail = @mEMail
      ORDER BY DESTTYP,EMail,RecId
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP,EMail,RecId
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP,EMail,RecId
    RETURN
  END

  IF @xLen < 82 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP AND 
      EMail >= @mEMail AND SUBSTRING(EMail,1,LEN(@mEMail)) = @mEMail
      ORDER BY DESTTYP,EMail,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_Key9')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_Key9]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_Key9] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mEMail varchar(80) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,80)

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

  IF @xLen = 82 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP AND 
      EMail = @mEMail
      ORDER BY DESTTYP desc,EMail desc,RecId desc
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP desc,EMail desc,RecId desc
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP desc,EMail desc,RecId desc
    RETURN
  END

  IF @xLen < 82 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen]  WHERE 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(EMail,1,LEN(@mEMail)) = @mEMail
      ORDER BY DESTTYP desc,EMail desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_First_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_KeyA] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE (DESTTYP < '10') ORDER BY DESTDEBNR,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_KeyA')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_KeyA] AS EXECUTE [dbo].[up_First_Adressen_KeyA]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_Last_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_KeyA] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE (DESTTYP < '10') ORDER BY DESTDEBNR desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_KeyA')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_KeyA] AS EXECUTE [dbo].[up_Last_Adressen_KeyA]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_Next_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_KeyA] @oldRecId integer AS
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE ((DESTDEBNR = @oldDESTDEBNR) AND (RecId > @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE ((DESTDEBNR > @oldDESTDEBNR)) AND ((DESTTYP < '10'))
    ORDER BY DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_KeyA] @oldRecId integer AS
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE ((DESTDEBNR = @oldDESTDEBNR) AND (RecId < @oldRecId)) AND ((DESTTYP < '10'))
    ORDER BY DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0)
    WHERE ((DESTDEBNR < @oldDESTDEBNR)) AND ((DESTTYP < '10'))
    ORDER BY DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_KeyA] @xKey char(250), @xLen integer AS
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR = @mDESTDEBNR
      AND ((DESTTYP < '10'))
      ORDER BY DESTDEBNR,RecId
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR >= @mDESTDEBNR AND SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      AND ((DESTTYP < '10'))
      ORDER BY DESTDEBNR,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_KeyA')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_KeyA]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_KeyA] @xKey char(250), @xLen integer AS
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)

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

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      DESTDEBNR = @mDESTDEBNR
      AND ((DESTTYP < '10'))
      ORDER BY DESTDEBNR desc,RecId desc
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key0) WHERE 
      SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      AND ((DESTTYP < '10'))
      ORDER BY DESTDEBNR desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_First_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_KeyB] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) ORDER BY DESTTYP,DESTDEBNR,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_KeyB')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_KeyB] AS EXECUTE [dbo].[up_First_Adressen_KeyB]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_Last_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_KeyB] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_KeyB')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_KeyB] AS EXECUTE [dbo].[up_Last_Adressen_KeyB]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_Next_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_KeyB] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTTYP = DESTTYP, @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP = @oldDESTTYP) AND (DESTDEBNR = @oldDESTDEBNR) AND (RecId > @oldRecId)
    ORDER BY DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP = @oldDESTTYP) AND (DESTDEBNR > @oldDESTDEBNR)
    ORDER BY DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP > @oldDESTTYP)
    ORDER BY DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_KeyB] @oldRecId integer AS
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldDESTTYP = DESTTYP, @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP = @oldDESTTYP) AND (DESTDEBNR = @oldDESTDEBNR) AND (RecId < @oldRecId)
    ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP = @oldDESTTYP) AND (DESTDEBNR < @oldDESTDEBNR)
    ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB)
    WHERE (DESTTYP < @oldDESTTYP)
    ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_KeyB] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,15)

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

  IF @xLen = 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP,DESTDEBNR,RecId
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen < 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR >= @mDESTDEBNR AND SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY DESTTYP,DESTDEBNR,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_KeyB')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_KeyB]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_KeyB] @xKey char(250), @xLen integer AS
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,2)
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,3,15)

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

  IF @xLen = 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen = 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP
      ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

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

  IF @xLen < 2 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen < 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyB) WHERE 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

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


-- logical key  ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
IF 0 < (select count(*) from sysindexes si inner join sysobjects so on so.[xtype] = 'U' and so.[name] = 'ut_Adressen' and so.[id] = si.[id] and si.[name] = 'Ik_KeyC')
  DROP INDEX [Ik_KeyC] ON [dbo].[ut_Adressen]
GO
IF 0 = (select count(*) from sysindexes si inner join sysobjects so on so.[xtype] = 'U' and so.[name] = 'ut_Adressen' and so.[id] = si.[id] and si.[name] = 'Ik_KeyC')
  CREATE INDEX [Ik_KeyC] ON [dbo].[ut_Adressen] (RefTo,DESTTYP,DESTDEBNR,RecId)
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_First_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_KeyC] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_KeyC')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_KeyC] AS EXECUTE [dbo].[up_First_Adressen_KeyC]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_Last_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_KeyC] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_KeyC')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_KeyC] AS EXECUTE [dbo].[up_Last_Adressen_KeyC]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_Next_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_KeyC] @oldRecId integer AS
  DECLARE @oldRefTo char(15)
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldRefTo = RefTo, @oldDESTTYP = DESTTYP, @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP = @oldDESTTYP) AND (DESTDEBNR = @oldDESTDEBNR) AND (RecId > @oldRecId)
    ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP = @oldDESTTYP) AND (DESTDEBNR > @oldDESTDEBNR)
    ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP > @oldDESTTYP)
    ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo > @oldRefTo)
    ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_KeyC] @oldRecId integer AS
  DECLARE @oldRefTo char(15)
  DECLARE @oldDESTTYP char(2)
  DECLARE @oldDESTDEBNR char(15)
  SELECT @oldRefTo = RefTo, @oldDESTTYP = DESTTYP, @oldDESTDEBNR = DESTDEBNR FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP = @oldDESTTYP) AND (DESTDEBNR = @oldDESTDEBNR) AND (RecId < @oldRecId)
    ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP = @oldDESTTYP) AND (DESTDEBNR < @oldDESTDEBNR)
    ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo = @oldRefTo) AND (DESTTYP < @oldDESTTYP)
    ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC)
    WHERE (RefTo < @oldRefTo)
    ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_KeyC] @xKey char(250), @xLen integer AS
  DECLARE @mRefTo char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,16,2)
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,18,15)

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

  IF @xLen = 32 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen = 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo >= @mRefTo AND SUBSTRING(RefTo,1,LEN(@mRefTo)) = @mRefTo
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen < 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP >= @mDESTTYP AND SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

  IF @xLen < 32 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR >= @mDESTDEBNR AND SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY RefTo,DESTTYP,DESTDEBNR,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_KeyC')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_KeyC]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_KeyC] @xKey char(250), @xLen integer AS
  DECLARE @mRefTo char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,15)
  DECLARE @mDESTTYP char(2) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,16,2)
  DECLARE @mDESTDEBNR char(15) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,18,15)

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

  IF @xLen = 32 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP AND 
      DESTDEBNR = @mDESTDEBNR
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen = 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen = 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

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

  IF @xLen < 15 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      SUBSTRING(RefTo,1,LEN(@mRefTo)) = @mRefTo
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen < 17 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      SUBSTRING(DESTTYP,1,LEN(@mDESTTYP)) = @mDESTTYP
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

  IF @xLen < 32 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_KeyC) WHERE 
      RefTo = @mRefTo AND 
      DESTTYP = @mDESTTYP AND 
      SUBSTRING(DESTDEBNR,1,LEN(@mDESTDEBNR)) = @mDESTDEBNR
      ORDER BY RefTo desc,DESTTYP desc,DESTDEBNR desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_First_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_KeyD] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) ORDER BY SUCHEN,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_KeyD')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_KeyD] AS EXECUTE [dbo].[up_First_Adressen_KeyD]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_Last_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_KeyD] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) ORDER BY SUCHEN desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_KeyD')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_KeyD] AS EXECUTE [dbo].[up_Last_Adressen_KeyD]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_Next_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_KeyD] @oldRecId integer AS
  DECLARE @oldSUCHEN char(40)
  SELECT @oldSUCHEN = SUCHEN FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE (SUCHEN = @oldSUCHEN) AND (RecId > @oldRecId)
    ORDER BY SUCHEN,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE (SUCHEN > @oldSUCHEN)
    ORDER BY SUCHEN,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_KeyD] @oldRecId integer AS
  DECLARE @oldSUCHEN char(40)
  SELECT @oldSUCHEN = SUCHEN FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE (SUCHEN = @oldSUCHEN) AND (RecId < @oldRecId)
    ORDER BY SUCHEN desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1)
    WHERE (SUCHEN < @oldSUCHEN)
    ORDER BY SUCHEN desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_KeyD] @xKey char(250), @xLen integer AS
  DECLARE @mSUCHEN char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN = @mSUCHEN
      ORDER BY SUCHEN,RecId
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN >= @mSUCHEN AND SUBSTRING(SUCHEN,1,LEN(@mSUCHEN)) = @mSUCHEN
      ORDER BY SUCHEN,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_KeyD')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_KeyD]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_KeyD] @xKey char(250), @xLen integer AS
  DECLARE @mSUCHEN char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUCHEN = @mSUCHEN
      ORDER BY SUCHEN desc,RecId desc
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key1) WHERE 
      SUBSTRING(SUCHEN,1,LEN(@mSUCHEN)) = @mSUCHEN
      ORDER BY SUCHEN desc,RecId desc
    RETURN
  END

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


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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_First_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_First_Adressen_KeyE] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) ORDER BY Name1,RecId
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_First_Adressen_KeyE')
  EXEC('ALTER PROCEDURE [dbo].[qp_First_Adressen_KeyE] AS EXECUTE [dbo].[up_First_Adressen_KeyE]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_Last_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_Last_Adressen_KeyE] AS
  SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) ORDER BY Name1 desc,RecId desc
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'qp_Last_Adressen_KeyE')
  EXEC('ALTER PROCEDURE [dbo].[qp_Last_Adressen_KeyE] AS EXECUTE [dbo].[up_Last_Adressen_KeyE]')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_Next_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_Next_Adressen_KeyE] @oldRecId integer AS
  DECLARE @oldName1 char(40)
  SELECT @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE (Name1 = @oldName1) AND (RecId > @oldRecId)
    ORDER BY Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE (Name1 > @oldName1)
    ORDER BY Name1,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_Prior_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_Prior_Adressen_KeyE] @oldRecId integer AS
  DECLARE @oldName1 char(40)
  SELECT @oldName1 = Name1 FROM [dbo].[ut_Adressen] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE (Name1 = @oldName1) AND (RecId < @oldRecId)
    ORDER BY Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2)
    WHERE (Name1 < @oldName1)
    ORDER BY Name1 desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_FindF_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_FindF_Adressen_KeyE] @xKey char(250), @xLen integer AS
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 = @mName1
      ORDER BY Name1,RecId
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 >= @mName1 AND SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      ORDER BY Name1,RecId
    RETURN
  END

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Adressen_KeyE')
  DROP PROCEDURE [dbo].[up_FindL_Adressen_KeyE]
GO
CREATE PROCEDURE [dbo].[up_FindL_Adressen_KeyE] @xKey char(250), @xLen integer AS
  DECLARE @mName1 char(40) = dbo.itcfunc_KeyToken_varchar(@xKey,@xLen,1,40)

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

  IF @xLen = 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      Name1 = @mName1
      ORDER BY Name1 desc,RecId desc
    RETURN
  END

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

  IF @xLen < 40 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Adressen] WITH(INDEX = Ik_Key2) WHERE 
      SUBSTRING(Name1,1,LEN(@mName1)) = @mName1
      ORDER BY Name1 desc,RecId desc
    RETURN
  END

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


