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 |
|
sp_wiz
Yak Posting Veteran
55 Posts |
Posted - 2001-06-18 : 10:23:55
|
| I have been using SP's for sometime now, but I am curious in the benfit of them if you have to pass parameters to them. (As they become dynamic).Likewise if you use a lot of IF statementsI have posted an example of an SP I used.RobpCREATE PROCEDURE [DIY_AddItem]@cartid int,@itemid int, @qty int,@action varchar(10),@NewCartID int output ASBEGINIF @action = 'AddItem' BEGIN IF (select count(*) from diy_cart_items where cart_id=@cartid and product_id = @itemid) > 0 Begin update diy_cart_items set quantity = quantity + @qty where cart_id = @cartid and product_id = @itemid Return(1) End ELSE Begin insert into diy_cart_items values (@cartid, @itemid, @qty, getdate()) Return(2) End END--- Get New Cart ID ----IF @action = 'NewCart' Begin Declare @newcart int Exec diy_newcart @newcart output select @newcartID = @newcart insert into diy_cart_items values (@newcartID, @itemid, @qty, getdate()) Return(3) End END |
|
|
|
|
|