Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
luvdairish
Starting Member
6 Posts |
Posted - 2007-05-17 : 09:00:05
|
| I'm creating a trigger. I can create it when I don't have the WHILE Loop syntax in there, but when I put the WHILE Loop in (that is the ONLY change), I get error:Incorrect syntax near '='.Can someone look at my code:declare @orderid as intdeclare @status as intdeclare @oQTY as intdeclare @newQTY as intdeclare @oProductID as intselect @orderid = orderid, @status = [status] from inserted where [status] = 1if (@status = 1) begin while (select @oProductID = ProductID, @oQTY = QTY from Custodial_Order_Details where OrderID = @orderid) begin select @newQTY = sum(QTY - @oQTY) from custodial_inventory where ProductID = @oProductID update custodial_inventory set QTY = @newQTY where ProductID = @oProductID end endTHANK YOU!!!! |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-17 : 09:18:45
|
What condition do you want to put for the WHILE loop?Something like this?while exists(select * from Custodial_Order_Detailswhere OrderID = @orderid)begin...end Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
luvdairish
Starting Member
6 Posts |
Posted - 2007-05-17 : 09:28:22
|
| Yes! That worked. But how do I grab those values (ProductID and QTY that we replaced with the *) and put them into variables for use in the proceeding statements? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-17 : 10:44:02
|
| [code]while exists(select * from Custodial_Order_Detailswhere OrderID = @orderid)begin select @oProductID = ProductID, @oQTY = QTY from Custodial_Order_Details where OrderID = @orderid...end[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|