Something I'm missing with condition?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rleroux
    New Member
    • Mar 2007
    • 3

    Something I'm missing with condition?

    Hi all,

    I have the following snippet of code in my trigger
    [HTML]SELECT @Currentqty = qtyonHand FROM tblProduct WHERE ProductID = @Product
    SELECT @CurrentReorder = ReorderPoint FROM tblProduct WHERE ProductID = @Product
    IF (@Currentqty < @CurrentReorder )
    BEGIN
    --PRINT 'Update will fire'
    BEGIN TRANSACTION ProductUpdate
    UPDATE tblProduct
    SET qtyonHand = qtyonHand + @OrderAmt
    WHERE ProductID = @Product
    COMMIT TRANSACTION ProductUpdate
    END
    ELSE
    BEGIN
    PRINT 'No need to order, Plenty of items are on hand.'
    END
    GO[/HTML]


    The following is what I'm using to add 50 ites to the qtyonHand

    [HTML]UPDATE tblProduct
    SET qtyonHand = qtyonHand + 50
    WHERE ProductID = 1[/HTML]

    What ends up happening is that the trasaction is actually firing and thus even if the condition (say 100<50) is False, 50 is still added then the PRINT fires.
    What am I not seeing?

    Tnx
Working...