------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_KundenProjektPreise')
BEGIN
CREATE TABLE [dbo].[ut_KundenProjektPreise]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[Table] integer DEFAULT 0
  ,[Key] char(20) DEFAULT ' '
  ,[LkzNr] char(20) DEFAULT ' '
  ,[AblDatum] datetime DEFAULT CONVERT(datetime,'1900-01-01',120)
  ,[AbwEKM] tinyint DEFAULT 0
  ,[PreisJe] float DEFAULT 0
  ,[Bruttoek] float DEFAULT 0
  ,[Rabatt1] float DEFAULT 0
  ,[Rabatt2] float DEFAULT 0
  ,[KeinNE] tinyint DEFAULT 0
  ,[KeinZubeh] tinyint DEFAULT 0
  ,[AbwAufMat] tinyint DEFAULT 0
  ,[AufMat] float DEFAULT 0
  ,[AbwVkm2] tinyint DEFAULT 0
  ,[Vkm2] float DEFAULT 0
  ,[MatJN] tinyint DEFAULT 0
  ,[AbwEKL] tinyint DEFAULT 0
  ,[Zeit] float DEFAULT 0
  ,[MLohnH] float DEFAULT 0
  ,[AbwAufLohn] tinyint DEFAULT 0
  ,[AufLohn] float DEFAULT 0
  ,[AbwVkl2] tinyint DEFAULT 0
  ,[Vkl2] float DEFAULT 0
  ,[LohnJN] tinyint DEFAULT 0
  ,[Vk2JN] tinyint DEFAULT 0
  CONSTRAINT [Pk_KundenProjektPreise]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_KundenProjektPreise_KeyDel')
  DROP TRIGGER [dbo].[tr_KundenProjektPreise_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_KundenProjektPreise_KeyUpd')
  DROP TRIGGER [dbo].[tr_KundenProjektPreise_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_KundenProjektPreise_Keys')
  DROP TABLE [dbo].[ut_KundenProjektPreise_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'Table')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Table] 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_KundenProjektPreise' and sc.[name] = 'Key')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Key] 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_KundenProjektPreise' and sc.[name] = 'LkzNr')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [LkzNr] 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_KundenProjektPreise' and sc.[name] = 'AblDatum')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AblDatum] 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_KundenProjektPreise' and sc.[name] = 'AbwEKM')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwEKM] 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_KundenProjektPreise' and sc.[name] = 'PreisJe')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [PreisJe] 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_KundenProjektPreise' and sc.[name] = 'Bruttoek')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Bruttoek] 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_KundenProjektPreise' and sc.[name] = 'Rabatt1')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Rabatt1] 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_KundenProjektPreise' and sc.[name] = 'Rabatt2')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Rabatt2] 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_KundenProjektPreise' and sc.[name] = 'KeinNE')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [KeinNE] 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_KundenProjektPreise' and sc.[name] = 'KeinZubeh')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [KeinZubeh] 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_KundenProjektPreise' and sc.[name] = 'AbwAufMat')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwAufMat] 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_KundenProjektPreise' and sc.[name] = 'AufMat')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AufMat] float NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'AbwVkm2')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwVkm2] 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_KundenProjektPreise' and sc.[name] = 'Vkm2')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Vkm2] 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_KundenProjektPreise' and sc.[name] = 'MatJN')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [MatJN] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'AbwEKL')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwEKL] 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_KundenProjektPreise' and sc.[name] = 'Zeit')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Zeit] float NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'MLohnH')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [MLohnH] 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_KundenProjektPreise' and sc.[name] = 'AbwAufLohn')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwAufLohn] 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_KundenProjektPreise' and sc.[name] = 'AufLohn')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AufLohn] float NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'AbwVkl2')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [AbwVkl2] 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_KundenProjektPreise' and sc.[name] = 'Vkl2')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Vkl2] 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_KundenProjektPreise' and sc.[name] = 'LohnJN')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [LohnJN] tinyint NOT NULL DEFAULT 0
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'Vk2JN')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ADD [Vk2JN] tinyint NOT NULL DEFAULT 0
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'Key')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ALTER COLUMN [Key] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_KundenProjektPreise' and sc.[name] = 'LkzNr')
BEGIN
  ALTER TABLE [dbo].[ut_KundenProjektPreise] ALTER COLUMN [LkzNr] char(20)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'KundenProjektPreise')
  DROP VIEW [dbo].[KundenProjektPreise]
GO
CREATE VIEW [dbo].[KundenProjektPreise] AS
  SELECT * FROM [dbo].[ut_KundenProjektPreise]
GO
CREATE TABLE [dbo].[ut_KundenProjektPreise_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(61) NOT NULL
  ,[Key01_Value] CHAR(61) NOT NULL
  CONSTRAINT [Pk_ut_KundenProjektPreise_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_KundenProjektPreise_KeyDel] ON [dbo].[ut_KundenProjektPreise]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_KundenProjektPreise_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_KundenProjektPreise_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(STR([Table],1,0)+convert(char(20),[Key])+convert(char(20),[LkzNr])+CONVERT(char(10),[AblDatum],120)+STR(RecId,10))
     ,UPPER(STR([Table],1,0)+convert(char(20),[LkzNr])+convert(char(20),[Key])+CONVERT(char(10),[AblDatum],120)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_KundenProjektPreise_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(STR([Table],1,0)+convert(char(20),[Key])+convert(char(20),[LkzNr])+CONVERT(char(10),[AblDatum],120)+STR([RecId],10))
   ,[Key01_Value] = UPPER(STR([Table],1,0)+convert(char(20),[LkzNr])+convert(char(20),[Key])+CONVERT(char(10),[AblDatum],120)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


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

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Upd_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_Upd_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_Upd_KundenProjektPreise]
  @RI integer
 ,@Parm_Table integer
 ,@Parm_Key char(20)
 ,@Parm_LkzNr char(20)
 ,@Parm_AblDatum datetime
 ,@Parm_AbwEKM tinyint
 ,@Parm_PreisJe float
 ,@Parm_Bruttoek float
 ,@Parm_Rabatt1 float
 ,@Parm_Rabatt2 float
 ,@Parm_KeinNE tinyint
 ,@Parm_KeinZubeh tinyint
 ,@Parm_AbwAufMat tinyint
 ,@Parm_AufMat float
 ,@Parm_AbwVkm2 tinyint
 ,@Parm_Vkm2 float
 ,@Parm_MatJN tinyint
 ,@Parm_AbwEKL tinyint
 ,@Parm_Zeit float
 ,@Parm_MLohnH float
 ,@Parm_AbwAufLohn tinyint
 ,@Parm_AufLohn float
 ,@Parm_AbwVkl2 tinyint
 ,@Parm_Vkl2 float
 ,@Parm_LohnJN tinyint
 ,@Parm_Vk2JN tinyint
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_KundenProjektPreise] SET
     [Table] = @Parm_Table
    ,[Key] = RTRIM(@Parm_Key)
    ,[LkzNr] = RTRIM(@Parm_LkzNr)
    ,[AblDatum] = @Parm_AblDatum
    ,[AbwEKM] = @Parm_AbwEKM
    ,[PreisJe] = @Parm_PreisJe
    ,[Bruttoek] = @Parm_Bruttoek
    ,[Rabatt1] = @Parm_Rabatt1
    ,[Rabatt2] = @Parm_Rabatt2
    ,[KeinNE] = @Parm_KeinNE
    ,[KeinZubeh] = @Parm_KeinZubeh
    ,[AbwAufMat] = @Parm_AbwAufMat
    ,[AufMat] = @Parm_AufMat
    ,[AbwVkm2] = @Parm_AbwVkm2
    ,[Vkm2] = @Parm_Vkm2
    ,[MatJN] = @Parm_MatJN
    ,[AbwEKL] = @Parm_AbwEKL
    ,[Zeit] = @Parm_Zeit
    ,[MLohnH] = @Parm_MLohnH
    ,[AbwAufLohn] = @Parm_AbwAufLohn
    ,[AufLohn] = @Parm_AufLohn
    ,[AbwVkl2] = @Parm_AbwVkl2
    ,[Vkl2] = @Parm_Vkl2
    ,[LohnJN] = @Parm_LohnJN
    ,[Vk2JN] = @Parm_Vk2JN
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_Sel_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_Sel_KundenProjektPreise]
  @RI integer
AS
SELECT
     [Table]
    ,[Key]
    ,[LkzNr]
    ,[AblDatum]
    ,[AbwEKM]
    ,[PreisJe]
    ,[Bruttoek]
    ,[Rabatt1]
    ,[Rabatt2]
    ,[KeinNE]
    ,[KeinZubeh]
    ,[AbwAufMat]
    ,[AufMat]
    ,[AbwVkm2]
    ,[Vkm2]
    ,[MatJN]
    ,[AbwEKL]
    ,[Zeit]
    ,[MLohnH]
    ,[AbwAufLohn]
    ,[AufLohn]
    ,[AbwVkl2]
    ,[Vkl2]
    ,[LohnJN]
    ,[Vk2JN]
  FROM [dbo].[ut_KundenProjektPreise]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_Del_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_Del_KundenProjektPreise]
  @RI integer
AS
  DELETE FROM [dbo].[ut_KundenProjektPreise] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_Reorg_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_Reorg_KundenProjektPreise]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_KundenProjektPreise] 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_KundenProjektPreise] 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_KundenProjektPreise] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_Append_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_Append_KundenProjektPreise]
  @Parm_Table integer
 ,@Parm_Key char(20)
 ,@Parm_LkzNr char(20)
 ,@Parm_AblDatum datetime
 ,@Parm_AbwEKM tinyint
 ,@Parm_PreisJe float
 ,@Parm_Bruttoek float
 ,@Parm_Rabatt1 float
 ,@Parm_Rabatt2 float
 ,@Parm_KeinNE tinyint
 ,@Parm_KeinZubeh tinyint
 ,@Parm_AbwAufMat tinyint
 ,@Parm_AufMat float
 ,@Parm_AbwVkm2 tinyint
 ,@Parm_Vkm2 float
 ,@Parm_MatJN tinyint
 ,@Parm_AbwEKL tinyint
 ,@Parm_Zeit float
 ,@Parm_MLohnH float
 ,@Parm_AbwAufLohn tinyint
 ,@Parm_AufLohn float
 ,@Parm_AbwVkl2 tinyint
 ,@Parm_Vkl2 float
 ,@Parm_LohnJN tinyint
 ,@Parm_Vk2JN tinyint
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_KundenProjektPreise])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_KundenProjektPreise] (
    RecId
   ,[Table]
   ,[Key]
   ,[LkzNr]
   ,[AblDatum]
   ,[AbwEKM]
   ,[PreisJe]
   ,[Bruttoek]
   ,[Rabatt1]
   ,[Rabatt2]
   ,[KeinNE]
   ,[KeinZubeh]
   ,[AbwAufMat]
   ,[AufMat]
   ,[AbwVkm2]
   ,[Vkm2]
   ,[MatJN]
   ,[AbwEKL]
   ,[Zeit]
   ,[MLohnH]
   ,[AbwAufLohn]
   ,[AufLohn]
   ,[AbwVkl2]
   ,[Vkl2]
   ,[LohnJN]
   ,[Vk2JN]
     ) VALUES (
    @NeueId
   ,@Parm_Table
   ,RTRIM(@Parm_Key)
   ,RTRIM(@Parm_LkzNr)
   ,@Parm_AblDatum
   ,@Parm_AbwEKM
   ,@Parm_PreisJe
   ,@Parm_Bruttoek
   ,@Parm_Rabatt1
   ,@Parm_Rabatt2
   ,@Parm_KeinNE
   ,@Parm_KeinZubeh
   ,@Parm_AbwAufMat
   ,@Parm_AufMat
   ,@Parm_AbwVkm2
   ,@Parm_Vkm2
   ,@Parm_MatJN
   ,@Parm_AbwEKL
   ,@Parm_Zeit
   ,@Parm_MLohnH
   ,@Parm_AbwAufLohn
   ,@Parm_AufLohn
   ,@Parm_AbwVkl2
   ,@Parm_Vkl2
   ,@Parm_LohnJN
   ,@Parm_Vk2JN
       )
  IF @@ERROR = 0
  BEGIN
    SELECT @NeueId AS RecId
    RETURN
  END
  SELECT 0 AS RecId
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_TrSel_KundenProjektPreise')
  DROP PROCEDURE [dbo].[up_TrSel_KundenProjektPreise]
GO
CREATE PROCEDURE [dbo].[up_TrSel_KundenProjektPreise]
AS
  SELECT   RecId,
      LTRIM(RTRIM([Key]))
      +LTRIM(RTRIM([LkzNr]))
    AS Data
  FROM     [dbo].[ut_KundenProjektPreise]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_KundenProjektPreise_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_First_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_Last_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_Prior_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_Next_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_Next50_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_FindL_KundenProjektPreise_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_KundenProjektPreise_Key00')
  DROP PROCEDURE [dbo].[up_FindF_KundenProjektPreise_Key00]
GO

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

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

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

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

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

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

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

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

CREATE INDEX [Ik_Key01] ON [dbo].[ut_KundenProjektPreise_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_First_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_Last_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_Prior_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_Next_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_Next50_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_FindL_KundenProjektPreise_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_KundenProjektPreise_Key01')
  DROP PROCEDURE [dbo].[up_FindF_KundenProjektPreise_Key01]
GO

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

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

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

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

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

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

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

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

