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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update with join?

Author  Topic 

Dabbler
Starting Member

7 Posts

Posted - 2005-02-12 : 08:56:46
Given two tables Products and Inventory, I'm trying to set the Inventory
QtyInStock = 0 where Products VendorID = 11
and Inventory.ProductID = Products.uid

My query generates the follwoing error:
"ADO error: Only one expression can be specified in the select list when a subquery is not introduced with EXISTS"

I tried using EXISTS but wound up setting all rows to 0!

UPDATE Inventory
SET QtyInStock = 0
WHERE (Inventory.ProductID IN
(SELECT Inventory.ProductID, Products.uid, Products.VendorId
FROM Inventory JOIN
Products ON Inventory.ProductID = Products.uid
WHERE (Products.VendorId = 11)))

Thanks for any help with this.



Dabbler

nr
SQLTeam MVY

12543 Posts

Posted - 2005-02-12 : 09:45:42
DOn't get carried away with brackets they're just confusing.

update Inventory
SET QtyInStock = 0
from Inventory i
join Products p
on Inventory.ProductID = Products.uid
and Products.VendorId = 11

your query would have been
UPDATE Inventory
SET QtyInStock = 0
WHERE Inventory.ProductID IN
(
SELECT Products.uid
FROM Products
WHERE Products.VendorId = 11
)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Dabbler
Starting Member

7 Posts

Posted - 2005-02-12 : 10:19:08
Sweet, thanks much, that did the trick.

your query would have been
UPDATE Inventory
SET QtyInStock = 0
WHERE Inventory.ProductID IN
(
SELECT Products.uid
FROM Products
WHERE Products.VendorId = 11
)





Dabbler
Go to Top of Page
   

- Advertisement -