What database is this?
Its for SQL Server. I didn't write it though.
What would this do to tbl_product if you ran this sql?
If I want to add 4 items to my shopping cart and there are 10 available then the product's stock count will be updated to 6.
If I want to add 4 items to my shopping cart but there are only 3 available then the product's stock count will be reduced by 3 (to zero) and the number of items that I'm able to add to my cart will be returned in @ActualOrderQty.
Can't you just implement the logic in C# and update and save an entity with the result of the calculation ?
Yes but doing this in one UPDATE saves me from having to SELECT the product row with an UPDLOCK followed by an UPDATE.
I think I could also use an OUTPUT clause!
http://msdn.microsoft.com/en-us/library/ms177564.aspx