Locked Triggers In My POS System

  • Sunday, April 08, 2012 9:25 AM
     
     

    Dear
    I have an accounting program (POS) I create 2 Triggers in sale table, but the program will be a bit slower I expect that this Triggers is the reason for the slow

    The first Trigger  Offers for lowering prices from period to period and if this Item was included in the offer and supply in the period the system will deduct according to the ratio


    ALTER TRIGGER [dbo].[AmtSaleUpdate] 
    ON [dbo].[Sale]
    AFTER INSERT

    AS
    DECLARE @SaleRate  Decimal(18,3)
    DECLARE @FrmDate   smalldatetime
    DECLARE @ToDate   smalldatetime
    declare @SaleCOOD  int
    SELECT    @SaleCOOD=SaleCOOD ,@SaleRate=SaleRate,@FrmDate=FrmDate,@ToDate=ToDate
    FROM         dbo.Offer
    where
     GETDATE() Between FrmDate and  ToDate
    and 
    Offer.SaleCOOD =(SELECT s.SaleCOOD
    FROM         dbo.Stock s
     JOIN inserted i ON s.ItemCode = i.Item_Code )


    BEGIN
    UPDATE Sale
    SET Sale.Rate_Sale=(Sale.Rate_Sale)-(Sale.Rate_Sale*@SaleRate/100),Sale.SaleCOOD=@SaleCOOD

    FROM         dbo.Sale INNER JOIN
                          dbo.Sale_Inv ON dbo.Sale.Inv_Code = dbo.Sale_Inv.Inv_Code INNER JOIN
                          dbo.Stock ON dbo.Sale.Item_Code = dbo.Stock.ItemCode
    where
    Sale.Nu=(select max(Nu) from sale)
    and
     Stock.SaleCOOD=@SaleCOOD
    and
    Sale_Inv.Date_Time Between @FrmDate and  @ToDate

    End

    Please help


    almunji

All Replies

  • Friday, April 20, 2012 8:18 AM
     
     

    Hello,

    I went through the trigger.  you want it to be optimized?