471,066 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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
Mar 3 '07 #1
0 804

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Dave | last post: by
5 posts views Thread by le0 | last post: by
3 posts views Thread by danceli | last post: by
33 posts views Thread by Stef Mientki | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.