------------------------------------------------------------
IF 0 = (SELECT count(*) from [sysobjects] where ([xtype] = 'U' or [xtype] = 'V') and [name] = 'ut_TenderPrice')
BEGIN
CREATE TABLE [dbo].[ut_TenderPrice]
(
   [RecId]  integer NOT NULL
  ,[MandId] integer DEFAULT 1
  ,[TenderNo] char(20) DEFAULT ' '
  ,[Tenderer] integer DEFAULT 0
  ,[GaebOZ] char(20) DEFAULT ' '
  ,[QtyTBD] tinyint DEFAULT 0
  ,[Qty] float DEFAULT 0
  ,[QU] char(6) DEFAULT ' '
  ,[UP] float DEFAULT 0
  ,[DscntPcnt] float DEFAULT 0
  ,[IT] float DEFAULT 0
  ,[QtyPurch] float DEFAULT 0
  ,[Descrip] char(50) DEFAULT ' '
  ,[Inquired] tinyint DEFAULT 0
  CONSTRAINT [Pk_TenderPrice]  PRIMARY KEY NONCLUSTERED ( [RecId] )
)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_TenderPrice_KeyDel')
  DROP TRIGGER [dbo].[tr_TenderPrice_KeyDel]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_TenderPrice_KeyUpd')
  DROP TRIGGER [dbo].[tr_TenderPrice_KeyUpd]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'U' and [name] = 'ut_TenderPrice_Keys')
  DROP TABLE [dbo].[ut_TenderPrice_Keys]
GO

IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'TenderNo')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [TenderNo] 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_TenderPrice' and sc.[name] = 'Tenderer')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [Tenderer] 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_TenderPrice' and sc.[name] = 'GaebOZ')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [GaebOZ] 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_TenderPrice' and sc.[name] = 'QtyTBD')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [QtyTBD] 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_TenderPrice' and sc.[name] = 'Qty')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [Qty] 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_TenderPrice' and sc.[name] = 'QU')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [QU] char(6) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'UP')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [UP] 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_TenderPrice' and sc.[name] = 'DscntPcnt')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [DscntPcnt] 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_TenderPrice' and sc.[name] = 'IT')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [IT] 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_TenderPrice' and sc.[name] = 'QtyPurch')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [QtyPurch] 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_TenderPrice' and sc.[name] = 'Descrip')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [Descrip] char(50) NOT NULL DEFAULT ' '
END
GO
IF 0 = (select count(*) from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'Inquired')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ADD [Inquired] 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_TenderPrice' and sc.[name] = 'TenderNo')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ALTER COLUMN [TenderNo] char(20)
END
GO
IF 20 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'GaebOZ')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ALTER COLUMN [GaebOZ] char(20)
END
GO
IF 6 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'QU')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ALTER COLUMN [QU] char(6)
END
GO
IF 50 > (select length from syscolumns sc inner join sysobjects so
        on sc.[id] = so.[id] and so.[name] = 'ut_TenderPrice' and sc.[name] = 'Descrip')
BEGIN
  ALTER TABLE [dbo].[ut_TenderPrice] ALTER COLUMN [Descrip] char(50)
END
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V' and [name] = 'TenderPrice')
  DROP VIEW [dbo].[TenderPrice]
GO
CREATE VIEW [dbo].[TenderPrice] AS
  SELECT * FROM [dbo].[ut_TenderPrice]
GO
CREATE TABLE [dbo].[ut_TenderPrice_Keys]
(
   [DataRecId]  integer NOT NULL
  ,[DataMandId] integer DEFAULT 1
  ,[Key00_Value] CHAR(58) NOT NULL
  ,[Key01_Value] CHAR(58) NOT NULL
  CONSTRAINT [Pk_ut_TenderPrice_Keys]  PRIMARY KEY NONCLUSTERED ( [DataRecId] )
)
GO
CREATE TRIGGER [dbo].[tr_TenderPrice_KeyDel] ON [dbo].[ut_TenderPrice]
FOR DELETE
AS
  SET NOCOUNT ON
  DELETE FROM [dbo].[ut_TenderPrice_Keys] WITH (SERIALIZABLE)
  WHERE [DataRecId] IN (SELECT [RecId] FROM DELETED)
GO

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

    INSERT INTO [dbo].[ut_TenderPrice_Keys] WITH (SERIALIZABLE)
    ([DataRecId],[DataMandId],[Key00_Value],[Key01_Value])
    (SELECT [RecId],[MandId]
     ,UPPER(convert(char(20),[TenderNo])+STR([Tenderer],8,0)+convert(char(20),[GaebOZ])+STR(RecId,10))
     ,UPPER(convert(char(20),[TenderNo])+convert(char(20),[GaebOZ])+STR([Tenderer],8,0)+STR(RecId,10))

    FROM INSERTED)
  END
  ELSE
  BEGIN
    UPDATE [dbo].[ut_TenderPrice_Keys] WITH (SERIALIZABLE) SET
    [Key00_Value] = UPPER(convert(char(20),[TenderNo])+STR([Tenderer],8,0)+convert(char(20),[GaebOZ])+STR([RecId],10))
   ,[Key01_Value] = UPPER(convert(char(20),[TenderNo])+convert(char(20),[GaebOZ])+STR([Tenderer],8,0)+STR([RecId],10))
    FROM INSERTED WHERE [DataRecId] = [RecId]
  END
GO

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


------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Add_TenderPrice')
  DROP PROCEDURE [dbo].[up_Add_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Add_TenderPrice] AS
  DECLARE @NeueId integer
  SET @NeueId = (SELECT MAX(RecId) from [dbo].[ut_TenderPrice])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_TenderPrice] (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_TenderPrice')
  DROP PROCEDURE [dbo].[up_Upd_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Upd_TenderPrice]
  @RI integer
 ,@Parm_TenderNo char(20)
 ,@Parm_Tenderer integer
 ,@Parm_GaebOZ char(20)
 ,@Parm_QtyTBD tinyint
 ,@Parm_Qty float
 ,@Parm_QU char(6)
 ,@Parm_UP float
 ,@Parm_DscntPcnt float
 ,@Parm_IT float
 ,@Parm_QtyPurch float
 ,@Parm_Descrip char(50)
 ,@Parm_Inquired tinyint
AS
--BEGIN TRANSACTION
UPDATE [dbo].[ut_TenderPrice] SET
     [TenderNo] = RTRIM(@Parm_TenderNo)
    ,[Tenderer] = @Parm_Tenderer
    ,[GaebOZ] = RTRIM(@Parm_GaebOZ)
    ,[QtyTBD] = @Parm_QtyTBD
    ,[Qty] = @Parm_Qty
    ,[QU] = RTRIM(@Parm_QU)
    ,[UP] = @Parm_UP
    ,[DscntPcnt] = @Parm_DscntPcnt
    ,[IT] = @Parm_IT
    ,[QtyPurch] = @Parm_QtyPurch
    ,[Descrip] = RTRIM(@Parm_Descrip)
    ,[Inquired] = @Parm_Inquired
  WHERE RecId = @RI
--COMMIT TRANSACTION
GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_TenderPrice')
  DROP PROCEDURE [dbo].[up_Sel_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Sel_TenderPrice]
  @RI integer
AS
SELECT
     [TenderNo]
    ,[Tenderer]
    ,[GaebOZ]
    ,[QtyTBD]
    ,[Qty]
    ,[QU]
    ,[UP]
    ,[DscntPcnt]
    ,[IT]
    ,[QtyPurch]
    ,[Descrip]
    ,[Inquired]
  FROM [dbo].[ut_TenderPrice]
  WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Del_TenderPrice')
  DROP PROCEDURE [dbo].[up_Del_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Del_TenderPrice]
  @RI integer
AS
  DELETE FROM [dbo].[ut_TenderPrice] WHERE RecId = @RI
GO
------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Reorg_TenderPrice')
  DROP PROCEDURE [dbo].[up_Reorg_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Reorg_TenderPrice]
  @bDbcc integer,@bRecId integer
AS
  IF (@bRecId = 1)
  BEGIN
    DECLARE  C        CURSOR FOR SELECT RecId FROM [dbo].[ut_TenderPrice] 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_TenderPrice] 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_TenderPrice] )
  END

GO

------------------------------------------------------------
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Append_TenderPrice')
  DROP PROCEDURE [dbo].[up_Append_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_Append_TenderPrice]
  @Parm_TenderNo char(20)
 ,@Parm_Tenderer integer
 ,@Parm_GaebOZ char(20)
 ,@Parm_QtyTBD tinyint
 ,@Parm_Qty float
 ,@Parm_QU char(6)
 ,@Parm_UP float
 ,@Parm_DscntPcnt float
 ,@Parm_IT float
 ,@Parm_QtyPurch float
 ,@Parm_Descrip char(50)
 ,@Parm_Inquired tinyint
AS
  DECLARE @NeueId    integer
  SET     @NeueId = (SELECT MAX(RecId) FROM [dbo].[ut_TenderPrice])
  IF @NeueId IS NULL SET @NeueId = 0
  SET @NeueId = @NeueId + 1
  INSERT INTO [dbo].[ut_TenderPrice] (
    RecId
   ,[TenderNo]
   ,[Tenderer]
   ,[GaebOZ]
   ,[QtyTBD]
   ,[Qty]
   ,[QU]
   ,[UP]
   ,[DscntPcnt]
   ,[IT]
   ,[QtyPurch]
   ,[Descrip]
   ,[Inquired]
     ) VALUES (
    @NeueId
   ,RTRIM(@Parm_TenderNo)
   ,@Parm_Tenderer
   ,RTRIM(@Parm_GaebOZ)
   ,@Parm_QtyTBD
   ,@Parm_Qty
   ,RTRIM(@Parm_QU)
   ,@Parm_UP
   ,@Parm_DscntPcnt
   ,@Parm_IT
   ,@Parm_QtyPurch
   ,RTRIM(@Parm_Descrip)
   ,@Parm_Inquired
       )
  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_TenderPrice')
  DROP PROCEDURE [dbo].[up_TrSel_TenderPrice]
GO
CREATE PROCEDURE [dbo].[up_TrSel_TenderPrice]
AS
  SELECT   RecId,
      LTRIM(RTRIM([TenderNo]))
      +LTRIM(RTRIM([GaebOZ]))
      +LTRIM(RTRIM([QU]))
      +LTRIM(RTRIM([Descrip]))
    AS Data
  FROM     [dbo].[ut_TenderPrice]
  WHERE    RecId > 0
  ORDER BY RecId
GO

CREATE INDEX [Ik_Key00] ON [dbo].[ut_TenderPrice_Keys]
( [Key00_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_First_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_Last_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_Prior_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_Next_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_Next50_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_FindL_TenderPrice_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_TenderPrice_Key00')
  DROP PROCEDURE [dbo].[up_FindF_TenderPrice_Key00]
GO

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

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

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

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

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

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

CREATE PROCEDURE [dbo].[up_FindF_TenderPrice_Key00] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key00_Value] AS Key_Value FROM [dbo].[ut_TenderPrice_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_TenderPrice_Key00] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_TenderPrice_Keys]
  WHERE [Key00_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key00_Value] DESC
GO

CREATE INDEX [Ik_Key01] ON [dbo].[ut_TenderPrice_Keys]
( [Key01_Value],[DataRecId] )
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_First_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_Last_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_Prior_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_Next_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_Prior50_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_Next50_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_FindL_TenderPrice_Key01]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_TenderPrice_Key01')
  DROP PROCEDURE [dbo].[up_FindF_TenderPrice_Key01]
GO

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

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

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

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

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

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

CREATE PROCEDURE [dbo].[up_FindF_TenderPrice_Key01] @xKey char(128),@xLen integer
AS
  SELECT a.[DataRecId] FROM
    ( SELECT TOP 1 [DataRecId],[Key01_Value] AS Key_Value FROM [dbo].[ut_TenderPrice_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_TenderPrice_Key01] @xKey char(128),@xLen integer
AS
  SELECT TOP 1 [DataRecId] FROM [dbo].[ut_TenderPrice_Keys]
  WHERE [Key01_Value] like SUBSTRING(@xKey,1,@xLen)+'%'
  ORDER BY [Key01_Value] DESC
GO

