igloo21 (1/10/2014)
Hello-I’m having a minor issue and I’m having trouble figuring out why. So basically all I want to do is update one column using the UPDATE and SELECT below. I’m expecting to update roughly 17,600 records which is what I get back when I run just the SELECT without the UPDATE. When I run the script with the UPDATE included I end up updating over 55,000 rows (in my test environment of course ?)
I think it may be something I’m doing wrong in the UPDATE part. Can someone please give me a hint what I’m doing wrong?
UPDATE Productss
SET HotLeadParticipant=0 WHERE EXISTS(
SELECT DISTINCT
a.BoxID
,a.BoxName
,p.ProductsID
,p.ProductsName
,p.HotLeadParticipant
FROM
dbo.ValidProducts vp
INNER JOIN dbo.BoxProducts ap
ON vp.BoxProductID = ap.BoxProductID
INNER JOIN dbo.Boxs a
ON ap.BoxID = a.BoxID
INNER JOIN dbo.tblProducts p
ON vp.ProductID = p.ProductsD
WHERE a.BoxID IN (297,
318,
337,
354,
397,
398,
504,
535,
557,
604,
733)
Also remember that it is only going to update the number of products which might be less then the number of rows returned in the select statement because there might be more than one row per product.