-- 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_Bedasoft_Benutzer')
BEGIN
CREATE TABLE [dbo].[ut_Bedasoft_Benutzer]
(
  [RecId]  integer NOT NULL
 ,[LogName] char(20) DEFAULT ''
 ,[LogCheck1] integer DEFAULT 0
 ,[LogCheck2] char(8) DEFAULT ''
 ,[Admin] tinyint DEFAULT 0
 ,[Prj_Neu] tinyint DEFAULT 0
 ,[Prj_Verw] tinyint DEFAULT 0
 ,[Prj_Loe] tinyint DEFAULT 0
 ,[Ang_Neu] tinyint DEFAULT 0
 ,[Ang_Verw] tinyint DEFAULT 0
 ,[Ang_Loe] tinyint DEFAULT 0
 ,[Auftr_Neu] tinyint DEFAULT 0
 ,[Auftr_Verw] tinyint DEFAULT 0
 ,[Auftr_Loe] tinyint DEFAULT 0
 ,[Rng_Neu] tinyint DEFAULT 0
 ,[Rng_Verw] tinyint DEFAULT 0
 ,[Rng_Loe] tinyint DEFAULT 0
 ,[Beleg_Verarb] tinyint DEFAULT 0
 ,[Aufmass] tinyint DEFAULT 0
 ,[Service] tinyint DEFAULT 0
 ,[Mahnwesen] tinyint DEFAULT 0
 ,[Ueberwachung] tinyint DEFAULT 0
 ,[Zeiterfassung] tinyint DEFAULT 0
 ,[Kassenbuch] tinyint DEFAULT 0
 ,[Lager] tinyint DEFAULT 0
 ,[Gaeb] tinyint DEFAULT 0
 ,[Wartung] tinyint DEFAULT 0
 ,[Kalkulation] tinyint DEFAULT 0
 ,[Mitarbeiter] tinyint DEFAULT 0
 ,[Lieferanten] tinyint DEFAULT 0
 ,[Adr_Neu] tinyint DEFAULT 0
 ,[Adr_Loe] tinyint DEFAULT 0
 ,[Stamm_Neu] tinyint DEFAULT 0
 ,[Stamm_Aend] tinyint DEFAULT 0
 ,[Stamm_Loe] tinyint DEFAULT 0
 ,[Datanorm] tinyint DEFAULT 0
 ,[StdImporte] tinyint DEFAULT 0
 ,[StdExporte] tinyint DEFAULT 0
 ,[Gruppe] char(30) DEFAULT ''
 ,[SCMenu] integer DEFAULT 0
 ,[Zeichen] char(10) DEFAULT ''
 ,[Adr_Listen] tinyint DEFAULT 0
 ,[MailRng] char(20) DEFAULT ''
  CONSTRAINT [Pk_Bedasoft_Benutzer]  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_Bedasoft_Benutzer_KeyDel')
  DROP TRIGGER [dbo].[tr_Bedasoft_Benutzer_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_Bedasoft_Benutzer_KeyUpd')
  DROP TRIGGER [dbo].[tr_Bedasoft_Benutzer_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_Bedasoft_Benutzer_Keys')
  DROP TABLE [dbo].[ut_Bedasoft_Benutzer_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_Bedasoft_Benutzer' and sc.[name] = 'LogName')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [LogName] 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_Bedasoft_Benutzer' and sc.[name] = 'LogCheck1')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [LogCheck1] 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_Bedasoft_Benutzer' and sc.[name] = 'LogCheck2')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [LogCheck2] char(8) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Admin')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Admin] 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_Bedasoft_Benutzer' and sc.[name] = 'Prj_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Prj_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Prj_Verw')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Prj_Verw] 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_Bedasoft_Benutzer' and sc.[name] = 'Prj_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Prj_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Ang_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Ang_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Ang_Verw')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Ang_Verw] 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_Bedasoft_Benutzer' and sc.[name] = 'Ang_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Ang_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Auftr_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Auftr_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Auftr_Verw')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Auftr_Verw] 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_Bedasoft_Benutzer' and sc.[name] = 'Auftr_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Auftr_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Rng_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Rng_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Rng_Verw')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Rng_Verw] 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_Bedasoft_Benutzer' and sc.[name] = 'Rng_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Rng_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Beleg_Verarb')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Beleg_Verarb] 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_Bedasoft_Benutzer' and sc.[name] = 'Aufmass')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Aufmass] 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_Bedasoft_Benutzer' and sc.[name] = 'Service')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Service] 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_Bedasoft_Benutzer' and sc.[name] = 'Mahnwesen')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Mahnwesen] 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_Bedasoft_Benutzer' and sc.[name] = 'Ueberwachung')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Ueberwachung] 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_Bedasoft_Benutzer' and sc.[name] = 'Zeiterfassung')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Zeiterfassung] 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_Bedasoft_Benutzer' and sc.[name] = 'Kassenbuch')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Kassenbuch] 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_Bedasoft_Benutzer' and sc.[name] = 'Lager')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Lager] 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_Bedasoft_Benutzer' and sc.[name] = 'Gaeb')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Gaeb] 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_Bedasoft_Benutzer' and sc.[name] = 'Wartung')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Wartung] 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_Bedasoft_Benutzer' and sc.[name] = 'Kalkulation')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Kalkulation] 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_Bedasoft_Benutzer' and sc.[name] = 'Mitarbeiter')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Mitarbeiter] 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_Bedasoft_Benutzer' and sc.[name] = 'Lieferanten')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Lieferanten] 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_Bedasoft_Benutzer' and sc.[name] = 'Adr_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Adr_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Adr_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Adr_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Stamm_Neu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Stamm_Neu] 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_Bedasoft_Benutzer' and sc.[name] = 'Stamm_Aend')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Stamm_Aend] 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_Bedasoft_Benutzer' and sc.[name] = 'Stamm_Loe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Stamm_Loe] 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_Bedasoft_Benutzer' and sc.[name] = 'Datanorm')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Datanorm] 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_Bedasoft_Benutzer' and sc.[name] = 'StdImporte')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [StdImporte] 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_Bedasoft_Benutzer' and sc.[name] = 'StdExporte')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [StdExporte] 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_Bedasoft_Benutzer' and sc.[name] = 'Gruppe')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Gruppe] char(30) NOT NULL DEFAULT ''
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'SCMenu')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [SCMenu] 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_Bedasoft_Benutzer' and sc.[name] = 'Zeichen')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Zeichen] 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_Bedasoft_Benutzer' and sc.[name] = 'Adr_Listen')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [Adr_Listen] 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_Bedasoft_Benutzer' and sc.[name] = 'MailRng')
BEGIN
  ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ADD [MailRng] char(20) NOT NULL DEFAULT ''
END
GO

-- check lengths of text fields
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogName'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogName'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [LogName] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogName'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogName'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [LogName] varchar(20)
END
GO
IF (8 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogCheck2'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogCheck2'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [LogCheck2] char(8)
END
GO
IF (8 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogCheck2'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'LogCheck2'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [LogCheck2] varchar(8)
END
GO
IF (30 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Gruppe'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Gruppe'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [Gruppe] char(30)
END
GO
IF (30 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Gruppe'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Gruppe'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [Gruppe] 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_Bedasoft_Benutzer' and sc.[name] = 'Zeichen'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Zeichen'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [Zeichen] char(10)
END
GO
IF (10 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Zeichen'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'Zeichen'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [Zeichen] varchar(10)
END
GO
IF (20 > (select sc.length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'MailRng'))
  AND (175 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'MailRng'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [MailRng] char(20)
END
GO
IF (20 > (select length from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'MailRng'))
  AND (167 = (select sc.xtype from syscolumns sc inner join sysobjects so on sc.[id] = so.[id] and so.[name] = 'ut_Bedasoft_Benutzer' and sc.[name] = 'MailRng'))
BEGIN
   ALTER TABLE [dbo].[ut_Bedasoft_Benutzer] ALTER COLUMN [MailRng] varchar(20)
END
GO

-- create dedicated view
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'Bedasoft_Benutzer')
  DROP VIEW [dbo].[Bedasoft_Benutzer]
GO
CREATE VIEW [dbo].[Bedasoft_Benutzer] AS
  SELECT [RecId]
 ,[LogName]
 ,[LogCheck1]
 ,[LogCheck2]
 ,[Admin]
 ,[Prj_Neu]
 ,[Prj_Verw]
 ,[Prj_Loe]
 ,[Ang_Neu]
 ,[Ang_Verw]
 ,[Ang_Loe]
 ,[Auftr_Neu]
 ,[Auftr_Verw]
 ,[Auftr_Loe]
 ,[Rng_Neu]
 ,[Rng_Verw]
 ,[Rng_Loe]
 ,[Beleg_Verarb]
 ,[Aufmass]
 ,[Service]
 ,[Mahnwesen]
 ,[Ueberwachung]
 ,[Zeiterfassung]
 ,[Kassenbuch]
 ,[Lager]
 ,[Gaeb]
 ,[Wartung]
 ,[Kalkulation]
 ,[Mitarbeiter]
 ,[Lieferanten]
 ,[Adr_Neu]
 ,[Adr_Loe]
 ,[Stamm_Neu]
 ,[Stamm_Aend]
 ,[Stamm_Loe]
 ,[Datanorm]
 ,[StdImporte]
 ,[StdExporte]
 ,[Gruppe]
 ,[SCMenu]
 ,[Zeichen]
 ,[Adr_Listen]
 ,[MailRng]
  FROM [dbo].[ut_Bedasoft_Benutzer]
GO


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

-- select with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_Sel_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_Sel_Bedasoft_Benutzer]  @mRI integer
AS
  SELECT
    [LogName]
   ,[LogCheck1]
   ,[LogCheck2]
   ,[Admin]
   ,[Prj_Neu]
   ,[Prj_Verw]
   ,[Prj_Loe]
   ,[Ang_Neu]
   ,[Ang_Verw]
   ,[Ang_Loe]
   ,[Auftr_Neu]
   ,[Auftr_Verw]
   ,[Auftr_Loe]
   ,[Rng_Neu]
   ,[Rng_Verw]
   ,[Rng_Loe]
   ,[Beleg_Verarb]
   ,[Aufmass]
   ,[Service]
   ,[Mahnwesen]
   ,[Ueberwachung]
   ,[Zeiterfassung]
   ,[Kassenbuch]
   ,[Lager]
   ,[Gaeb]
   ,[Wartung]
   ,[Kalkulation]
   ,[Mitarbeiter]
   ,[Lieferanten]
   ,[Adr_Neu]
   ,[Adr_Loe]
   ,[Stamm_Neu]
   ,[Stamm_Aend]
   ,[Stamm_Loe]
   ,[Datanorm]
   ,[StdImporte]
   ,[StdExporte]
   ,[Gruppe]
   ,[SCMenu]
   ,[Zeichen]
   ,[Adr_Listen]
   ,[MailRng]
  FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId = @mRI
GO

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

-- insert with classic client
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_Append_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_Append_Bedasoft_Benutzer]
   @Param_LogName char(20)
  ,@Param_LogCheck1 integer
  ,@Param_LogCheck2 char(8)
  ,@Param_Admin tinyint
  ,@Param_Prj_Neu tinyint
  ,@Param_Prj_Verw tinyint
  ,@Param_Prj_Loe tinyint
  ,@Param_Ang_Neu tinyint
  ,@Param_Ang_Verw tinyint
  ,@Param_Ang_Loe tinyint
  ,@Param_Auftr_Neu tinyint
  ,@Param_Auftr_Verw tinyint
  ,@Param_Auftr_Loe tinyint
  ,@Param_Rng_Neu tinyint
  ,@Param_Rng_Verw tinyint
  ,@Param_Rng_Loe tinyint
  ,@Param_Beleg_Verarb tinyint
  ,@Param_Aufmass tinyint
  ,@Param_Service tinyint
  ,@Param_Mahnwesen tinyint
  ,@Param_Ueberwachung tinyint
  ,@Param_Zeiterfassung tinyint
  ,@Param_Kassenbuch tinyint
  ,@Param_Lager tinyint
  ,@Param_Gaeb tinyint
  ,@Param_Wartung tinyint
  ,@Param_Kalkulation tinyint
  ,@Param_Mitarbeiter tinyint
  ,@Param_Lieferanten tinyint
  ,@Param_Adr_Neu tinyint
  ,@Param_Adr_Loe tinyint
  ,@Param_Stamm_Neu tinyint
  ,@Param_Stamm_Aend tinyint
  ,@Param_Stamm_Loe tinyint
  ,@Param_Datanorm tinyint
  ,@Param_StdImporte tinyint
  ,@Param_StdExporte tinyint
  ,@Param_Gruppe char(30)
  ,@Param_SCMenu integer
  ,@Param_Zeichen char(10)
  ,@Param_Adr_Listen tinyint
  ,@Param_MailRng char(20)
AS
  DECLARE @NeueId integer
  DECLARE @m_CountDown integer = 10
  WHILE @m_CountDown > 0 BEGIN
    BEGIN TRANSACTION
    BEGIN TRY
      SET @NeueId = dbo.itcfunc_NextRecId_Bedasoft_Benutzer()
      INSERT INTO [dbo].[ut_Bedasoft_Benutzer] (RecId
        ,[LogName]
        ,[LogCheck1]
        ,[LogCheck2]
        ,[Admin]
        ,[Prj_Neu]
        ,[Prj_Verw]
        ,[Prj_Loe]
        ,[Ang_Neu]
        ,[Ang_Verw]
        ,[Ang_Loe]
        ,[Auftr_Neu]
        ,[Auftr_Verw]
        ,[Auftr_Loe]
        ,[Rng_Neu]
        ,[Rng_Verw]
        ,[Rng_Loe]
        ,[Beleg_Verarb]
        ,[Aufmass]
        ,[Service]
        ,[Mahnwesen]
        ,[Ueberwachung]
        ,[Zeiterfassung]
        ,[Kassenbuch]
        ,[Lager]
        ,[Gaeb]
        ,[Wartung]
        ,[Kalkulation]
        ,[Mitarbeiter]
        ,[Lieferanten]
        ,[Adr_Neu]
        ,[Adr_Loe]
        ,[Stamm_Neu]
        ,[Stamm_Aend]
        ,[Stamm_Loe]
        ,[Datanorm]
        ,[StdImporte]
        ,[StdExporte]
        ,[Gruppe]
        ,[SCMenu]
        ,[Zeichen]
        ,[Adr_Listen]
        ,[MailRng]
          ) VALUES (@NeueId
        ,UPPER(RTRIM(@Param_LogName))
        ,@Param_LogCheck1
        ,RTRIM(@Param_LogCheck2)
        ,@Param_Admin
        ,@Param_Prj_Neu
        ,@Param_Prj_Verw
        ,@Param_Prj_Loe
        ,@Param_Ang_Neu
        ,@Param_Ang_Verw
        ,@Param_Ang_Loe
        ,@Param_Auftr_Neu
        ,@Param_Auftr_Verw
        ,@Param_Auftr_Loe
        ,@Param_Rng_Neu
        ,@Param_Rng_Verw
        ,@Param_Rng_Loe
        ,@Param_Beleg_Verarb
        ,@Param_Aufmass
        ,@Param_Service
        ,@Param_Mahnwesen
        ,@Param_Ueberwachung
        ,@Param_Zeiterfassung
        ,@Param_Kassenbuch
        ,@Param_Lager
        ,@Param_Gaeb
        ,@Param_Wartung
        ,@Param_Kalkulation
        ,@Param_Mitarbeiter
        ,@Param_Lieferanten
        ,@Param_Adr_Neu
        ,@Param_Adr_Loe
        ,@Param_Stamm_Neu
        ,@Param_Stamm_Aend
        ,@Param_Stamm_Loe
        ,@Param_Datanorm
        ,@Param_StdImporte
        ,@Param_StdExporte
        ,UPPER(RTRIM(@Param_Gruppe))
        ,@Param_SCMenu
        ,RTRIM(@Param_Zeichen)
        ,@Param_Adr_Listen
        ,RTRIM(@Param_MailRng)
          )
      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_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_Add_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_Add_Bedasoft_Benutzer]
AS
  DECLARE @NeueId integer = dbo.itcfunc_NextRecId_Bedasoft_Benutzer()
  INSERT INTO [dbo].[ut_Bedasoft_Benutzer] (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_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_Upd_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_Upd_Bedasoft_Benutzer] @mRI integer
  ,@Param_LogName char(20)
  ,@Param_LogCheck1 integer
  ,@Param_LogCheck2 char(8)
  ,@Param_Admin tinyint
  ,@Param_Prj_Neu tinyint
  ,@Param_Prj_Verw tinyint
  ,@Param_Prj_Loe tinyint
  ,@Param_Ang_Neu tinyint
  ,@Param_Ang_Verw tinyint
  ,@Param_Ang_Loe tinyint
  ,@Param_Auftr_Neu tinyint
  ,@Param_Auftr_Verw tinyint
  ,@Param_Auftr_Loe tinyint
  ,@Param_Rng_Neu tinyint
  ,@Param_Rng_Verw tinyint
  ,@Param_Rng_Loe tinyint
  ,@Param_Beleg_Verarb tinyint
  ,@Param_Aufmass tinyint
  ,@Param_Service tinyint
  ,@Param_Mahnwesen tinyint
  ,@Param_Ueberwachung tinyint
  ,@Param_Zeiterfassung tinyint
  ,@Param_Kassenbuch tinyint
  ,@Param_Lager tinyint
  ,@Param_Gaeb tinyint
  ,@Param_Wartung tinyint
  ,@Param_Kalkulation tinyint
  ,@Param_Mitarbeiter tinyint
  ,@Param_Lieferanten tinyint
  ,@Param_Adr_Neu tinyint
  ,@Param_Adr_Loe tinyint
  ,@Param_Stamm_Neu tinyint
  ,@Param_Stamm_Aend tinyint
  ,@Param_Stamm_Loe tinyint
  ,@Param_Datanorm tinyint
  ,@Param_StdImporte tinyint
  ,@Param_StdExporte tinyint
  ,@Param_Gruppe char(30)
  ,@Param_SCMenu integer
  ,@Param_Zeichen char(10)
  ,@Param_Adr_Listen tinyint
  ,@Param_MailRng char(20)
AS
  UPDATE [dbo].[ut_Bedasoft_Benutzer] SET
    [LogName] = UPPER(RTRIM(@Param_LogName))
   ,[LogCheck1] = @Param_LogCheck1
   ,[LogCheck2] = RTRIM(@Param_LogCheck2)
   ,[Admin] = @Param_Admin
   ,[Prj_Neu] = @Param_Prj_Neu
   ,[Prj_Verw] = @Param_Prj_Verw
   ,[Prj_Loe] = @Param_Prj_Loe
   ,[Ang_Neu] = @Param_Ang_Neu
   ,[Ang_Verw] = @Param_Ang_Verw
   ,[Ang_Loe] = @Param_Ang_Loe
   ,[Auftr_Neu] = @Param_Auftr_Neu
   ,[Auftr_Verw] = @Param_Auftr_Verw
   ,[Auftr_Loe] = @Param_Auftr_Loe
   ,[Rng_Neu] = @Param_Rng_Neu
   ,[Rng_Verw] = @Param_Rng_Verw
   ,[Rng_Loe] = @Param_Rng_Loe
   ,[Beleg_Verarb] = @Param_Beleg_Verarb
   ,[Aufmass] = @Param_Aufmass
   ,[Service] = @Param_Service
   ,[Mahnwesen] = @Param_Mahnwesen
   ,[Ueberwachung] = @Param_Ueberwachung
   ,[Zeiterfassung] = @Param_Zeiterfassung
   ,[Kassenbuch] = @Param_Kassenbuch
   ,[Lager] = @Param_Lager
   ,[Gaeb] = @Param_Gaeb
   ,[Wartung] = @Param_Wartung
   ,[Kalkulation] = @Param_Kalkulation
   ,[Mitarbeiter] = @Param_Mitarbeiter
   ,[Lieferanten] = @Param_Lieferanten
   ,[Adr_Neu] = @Param_Adr_Neu
   ,[Adr_Loe] = @Param_Adr_Loe
   ,[Stamm_Neu] = @Param_Stamm_Neu
   ,[Stamm_Aend] = @Param_Stamm_Aend
   ,[Stamm_Loe] = @Param_Stamm_Loe
   ,[Datanorm] = @Param_Datanorm
   ,[StdImporte] = @Param_StdImporte
   ,[StdExporte] = @Param_StdExporte
   ,[Gruppe] = UPPER(RTRIM(@Param_Gruppe))
   ,[SCMenu] = @Param_SCMenu
   ,[Zeichen] = RTRIM(@Param_Zeichen)
   ,[Adr_Listen] = @Param_Adr_Listen
   ,[MailRng] = RTRIM(@Param_MailRng)
  WHERE RecId = @mRI
GO

-- update with modern clients
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd2_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_Upd2_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_Upd2_Bedasoft_Benutzer] @Param_RecId varchar(20)
  ,@Param_LogName varchar(20)
  ,@Param_LogCheck1 varchar(2)
  ,@Param_LogCheck2 varchar(8)
  ,@Param_Admin varchar(1)
  ,@Param_Prj_Neu varchar(1)
  ,@Param_Prj_Verw varchar(1)
  ,@Param_Prj_Loe varchar(1)
  ,@Param_Ang_Neu varchar(1)
  ,@Param_Ang_Verw varchar(1)
  ,@Param_Ang_Loe varchar(1)
  ,@Param_Auftr_Neu varchar(1)
  ,@Param_Auftr_Verw varchar(1)
  ,@Param_Auftr_Loe varchar(1)
  ,@Param_Rng_Neu varchar(1)
  ,@Param_Rng_Verw varchar(1)
  ,@Param_Rng_Loe varchar(1)
  ,@Param_Beleg_Verarb varchar(1)
  ,@Param_Aufmass varchar(1)
  ,@Param_Service varchar(1)
  ,@Param_Mahnwesen varchar(1)
  ,@Param_Ueberwachung varchar(1)
  ,@Param_Zeiterfassung varchar(1)
  ,@Param_Kassenbuch varchar(1)
  ,@Param_Lager varchar(1)
  ,@Param_Gaeb varchar(1)
  ,@Param_Wartung varchar(1)
  ,@Param_Kalkulation varchar(1)
  ,@Param_Mitarbeiter varchar(1)
  ,@Param_Lieferanten varchar(1)
  ,@Param_Adr_Neu varchar(1)
  ,@Param_Adr_Loe varchar(1)
  ,@Param_Stamm_Neu varchar(1)
  ,@Param_Stamm_Aend varchar(1)
  ,@Param_Stamm_Loe varchar(1)
  ,@Param_Datanorm varchar(1)
  ,@Param_StdImporte varchar(1)
  ,@Param_StdExporte varchar(1)
  ,@Param_Gruppe varchar(30)
  ,@Param_SCMenu varchar(4)
  ,@Param_Zeichen varchar(10)
  ,@Param_Adr_Listen varchar(1)
  ,@Param_MailRng varchar(20)
AS
  DECLARE @mRI integer = dbo.itcfunc_integer(@Param_RecId)
  UPDATE [dbo].[ut_Bedasoft_Benutzer] SET
    [LogName] = UPPER(RTRIM(@Param_LogName))
   ,[LogCheck1] = dbo.itcfunc_integer(@Param_LogCheck1)
   ,[LogCheck2] = RTRIM(@Param_LogCheck2)
   ,[Admin] = dbo.itcfunc_integer(@Param_Admin)
   ,[Prj_Neu] = dbo.itcfunc_integer(@Param_Prj_Neu)
   ,[Prj_Verw] = dbo.itcfunc_integer(@Param_Prj_Verw)
   ,[Prj_Loe] = dbo.itcfunc_integer(@Param_Prj_Loe)
   ,[Ang_Neu] = dbo.itcfunc_integer(@Param_Ang_Neu)
   ,[Ang_Verw] = dbo.itcfunc_integer(@Param_Ang_Verw)
   ,[Ang_Loe] = dbo.itcfunc_integer(@Param_Ang_Loe)
   ,[Auftr_Neu] = dbo.itcfunc_integer(@Param_Auftr_Neu)
   ,[Auftr_Verw] = dbo.itcfunc_integer(@Param_Auftr_Verw)
   ,[Auftr_Loe] = dbo.itcfunc_integer(@Param_Auftr_Loe)
   ,[Rng_Neu] = dbo.itcfunc_integer(@Param_Rng_Neu)
   ,[Rng_Verw] = dbo.itcfunc_integer(@Param_Rng_Verw)
   ,[Rng_Loe] = dbo.itcfunc_integer(@Param_Rng_Loe)
   ,[Beleg_Verarb] = dbo.itcfunc_integer(@Param_Beleg_Verarb)
   ,[Aufmass] = dbo.itcfunc_integer(@Param_Aufmass)
   ,[Service] = dbo.itcfunc_integer(@Param_Service)
   ,[Mahnwesen] = dbo.itcfunc_integer(@Param_Mahnwesen)
   ,[Ueberwachung] = dbo.itcfunc_integer(@Param_Ueberwachung)
   ,[Zeiterfassung] = dbo.itcfunc_integer(@Param_Zeiterfassung)
   ,[Kassenbuch] = dbo.itcfunc_integer(@Param_Kassenbuch)
   ,[Lager] = dbo.itcfunc_integer(@Param_Lager)
   ,[Gaeb] = dbo.itcfunc_integer(@Param_Gaeb)
   ,[Wartung] = dbo.itcfunc_integer(@Param_Wartung)
   ,[Kalkulation] = dbo.itcfunc_integer(@Param_Kalkulation)
   ,[Mitarbeiter] = dbo.itcfunc_integer(@Param_Mitarbeiter)
   ,[Lieferanten] = dbo.itcfunc_integer(@Param_Lieferanten)
   ,[Adr_Neu] = dbo.itcfunc_integer(@Param_Adr_Neu)
   ,[Adr_Loe] = dbo.itcfunc_integer(@Param_Adr_Loe)
   ,[Stamm_Neu] = dbo.itcfunc_integer(@Param_Stamm_Neu)
   ,[Stamm_Aend] = dbo.itcfunc_integer(@Param_Stamm_Aend)
   ,[Stamm_Loe] = dbo.itcfunc_integer(@Param_Stamm_Loe)
   ,[Datanorm] = dbo.itcfunc_integer(@Param_Datanorm)
   ,[StdImporte] = dbo.itcfunc_integer(@Param_StdImporte)
   ,[StdExporte] = dbo.itcfunc_integer(@Param_StdExporte)
   ,[Gruppe] = UPPER(RTRIM(@Param_Gruppe))
   ,[SCMenu] = dbo.itcfunc_integer(@Param_SCMenu)
   ,[Zeichen] = RTRIM(@Param_Zeichen)
   ,[Adr_Listen] = dbo.itcfunc_integer(@Param_Adr_Listen)
   ,[MailRng] = RTRIM(@Param_MailRng)
  WHERE RecId = @mRI

  EXECUTE [dbo].[up_Sel2_Bedasoft_Benutzer] @mRI
GO

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

-- text index
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_Bedasoft_Benutzer')
  DROP PROCEDURE [dbo].[up_TrSel_Bedasoft_Benutzer]
GO
CREATE PROCEDURE [dbo].[up_TrSel_Bedasoft_Benutzer]
AS
  SELECT RecId,
    LTRIM(RTRIM([LogName]))
   +LTRIM(RTRIM([LogCheck2]))
   +LTRIM(RTRIM([Gruppe]))
   +LTRIM(RTRIM([Zeichen]))
   +LTRIM(RTRIM([MailRng]))
  AS Data FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId > 0 ORDER BY RecId
GO

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

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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bedasoft_Benutzer_Key0')
  DROP PROCEDURE [dbo].[up_Next_Bedasoft_Benutzer_Key0]
GO
CREATE PROCEDURE [dbo].[up_Next_Bedasoft_Benutzer_Key0] @oldRecId integer AS
  DECLARE @oldLogName char(20)
  SELECT @oldLogName = LogName FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0)
    WHERE (LogName > @oldLogName)
    ORDER BY LogName,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_Bedasoft_Benutzer_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_Next_Bedasoft_Benutzer_Key0] @oldRecId integer AS EXECUTE [dbo].[up_Next_Bedasoft_Benutzer_Key0] @oldRecId')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bedasoft_Benutzer_Key0')
  DROP PROCEDURE [dbo].[up_Prior_Bedasoft_Benutzer_Key0]
GO
CREATE PROCEDURE [dbo].[up_Prior_Bedasoft_Benutzer_Key0] @oldRecId integer AS
  DECLARE @oldLogName char(20)
  SELECT @oldLogName = LogName FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0)
    WHERE (LogName < @oldLogName)
    ORDER BY LogName 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_Bedasoft_Benutzer_Key0')
  EXEC('ALTER PROCEDURE [dbo].[qp_Prior_Bedasoft_Benutzer_Key0] @oldRecId integer AS EXECUTE [dbo].[up_Prior_Bedasoft_Benutzer_Key0] @oldRecId')
GO

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

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

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

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

  IF @xLen = 20 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0) WHERE 
      LogName = @mLogName
      ORDER BY LogName,RecId
    RETURN
  END

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

  IF @xLen < 20 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0) WHERE 
      LogName >= @mLogName AND SUBSTRING(LogName,1,LEN(@mLogName)) = @mLogName
      ORDER BY LogName,RecId
    RETURN
  END

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

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

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

  IF @xLen = 20 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0) WHERE 
      LogName = @mLogName
      ORDER BY LogName desc,RecId desc
    RETURN
  END

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

  IF @xLen < 20 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key0) WHERE 
      SUBSTRING(LogName,1,LEN(@mLogName)) = @mLogName
      ORDER BY LogName desc,RecId desc
    RETURN
  END

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


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

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

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

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bedasoft_Benutzer_Key1')
  DROP PROCEDURE [dbo].[up_Next_Bedasoft_Benutzer_Key1]
GO
CREATE PROCEDURE [dbo].[up_Next_Bedasoft_Benutzer_Key1] @oldRecId integer AS
  DECLARE @oldGruppe char(30)
  DECLARE @oldLogName char(20)
  SELECT @oldGruppe = Gruppe, @oldLogName = LogName FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

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

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1)
    WHERE (Gruppe = @oldGruppe) AND (LogName > @oldLogName)
    ORDER BY Gruppe,LogName,RecId
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1)
    WHERE (Gruppe > @oldGruppe)
    ORDER BY Gruppe,LogName,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_Bedasoft_Benutzer_Key1')
  EXEC('ALTER PROCEDURE [dbo].[qp_Next_Bedasoft_Benutzer_Key1] @oldRecId integer AS EXECUTE [dbo].[up_Next_Bedasoft_Benutzer_Key1] @oldRecId')
GO

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bedasoft_Benutzer_Key1')
  DROP PROCEDURE [dbo].[up_Prior_Bedasoft_Benutzer_Key1]
GO
CREATE PROCEDURE [dbo].[up_Prior_Bedasoft_Benutzer_Key1] @oldRecId integer AS
  DECLARE @oldGruppe char(30)
  DECLARE @oldLogName char(20)
  SELECT @oldGruppe = Gruppe, @oldLogName = LogName FROM [dbo].[ut_Bedasoft_Benutzer] WHERE RecId = @oldRecId

  DECLARE @newRecId integer

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

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1)
    WHERE (Gruppe = @oldGruppe) AND (LogName < @oldLogName)
    ORDER BY Gruppe desc,LogName desc,RecId desc
  IF @newRecId <> 0 BEGIN
    SELECT @newRecId AS RecId
    RETURN
  END

  SELECT TOP 1 @newRecId = ISNULL(RecId,0) FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1)
    WHERE (Gruppe < @oldGruppe)
    ORDER BY Gruppe desc,LogName 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_Bedasoft_Benutzer_Key1')
  EXEC('ALTER PROCEDURE [dbo].[qp_Prior_Bedasoft_Benutzer_Key1] @oldRecId integer AS EXECUTE [dbo].[up_Prior_Bedasoft_Benutzer_Key1] @oldRecId')
GO

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

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

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

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

  IF @xLen = 50 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe AND 
      LogName = @mLogName
      ORDER BY Gruppe,LogName,RecId
    RETURN
  END

  IF @xLen = 30 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe
      ORDER BY Gruppe,LogName,RecId
    RETURN
  END

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

  IF @xLen < 30 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe >= @mGruppe AND SUBSTRING(Gruppe,1,LEN(@mGruppe)) = @mGruppe
      ORDER BY Gruppe,LogName,RecId
    RETURN
  END

  IF @xLen < 50 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe AND 
      LogName >= @mLogName AND SUBSTRING(LogName,1,LEN(@mLogName)) = @mLogName
      ORDER BY Gruppe,LogName,RecId
    RETURN
  END

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

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

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

  IF @xLen = 50 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe AND 
      LogName = @mLogName
      ORDER BY Gruppe desc,LogName desc,RecId desc
    RETURN
  END

  IF @xLen = 30 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe
      ORDER BY Gruppe desc,LogName desc,RecId desc
    RETURN
  END

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

  IF @xLen < 30 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      SUBSTRING(Gruppe,1,LEN(@mGruppe)) = @mGruppe
      ORDER BY Gruppe desc,LogName desc,RecId desc
    RETURN
  END

  IF @xLen < 50 BEGIN
    SELECT TOP 1 RecId FROM [dbo].[ut_Bedasoft_Benutzer] WITH(INDEX = Ik_Key1) WHERE 
      Gruppe = @mGruppe AND 
      SUBSTRING(LogName,1,LEN(@mLogName)) = @mLogName
      ORDER BY Gruppe desc,LogName desc,RecId desc
    RETURN
  END

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


