The way to do it is to join the two tables together then perform a self-update.
UPDATE ProductSo what have I done there? Well the first two lines instruct the dbms to update the Product table, altering the price. The second two lines provide a join of the 2 tables we are using and an interim relation that the Update can use as it's source. At table of 250,000 records took 3 seconds to update with this method but over 30 minutes using a cursor so the benefits are huge.
SET Price = NewPrice
FROM Product
INNER JOIN UpdatedProduct ON UpdatedProduct .ProductId = Product.ProductId

2 comments:
This is great! Just what I was looking for, thanks very much.
Thanx... :-)
Just what I needed.
Post a Comment