Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bulk load method??
Message
 
 
To
18/04/2006 08:30:57
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01114251
Message ID:
01114460
Views:
20
This message has been marked as the solution to the initial question of the thread.
Try
UPDATE tProducts 
    SET CurStockOnHand = CurStockOnHand + inserted.StockAdded - inserted.StockRemoved 
  FROM tProducts 
  JOIN inserted ON inserted.ProductID = tProducts.ProductID
>I have the following code in a trigger which updates a filed in another table. I would like to be able to do bulk inserts without using a cursor, but am not sure how to do this in this case. Any and all help is very appriciated.
>
>====================================================
>CREATE TRIGGER trUpdateCurrentStock ON dbo.tStockAvailable
>FOR INSERT
>AS
>
>DECLARE @ProductID INT,
> @StockAvailID INT,
> @CurrentStock INT
>
>SET @ProductID = (SELECT ProductID FROM INSERTED)
>SET @StockAvailID = (SELECT StockAvailID FROM INSERTED)
>
>SET @CurrentStock = (SELECT CurStockOnHand FROM tProducts
> WHERE ProductID = @ProductID) +
> (SELECT StockAdded FROM INSERTED) -
> (SELECT StockRemoved FROM INSERTED)
>
>UPDATE tProducts
> SET CurStockOnHand = @CurrentStock
> WHERE ProductID = @ProductID
>=====================================================
>
>P.S. - tProducts and tStockAvailable are related by ProductID.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform