UPDATE query with Select from two databases

Hello,
I have to update a column in one database based on a select query that is between two databases checking for a null. This is what I have:

UPDATE db1.dbo.products  
SET active = '0'
FROM (SELECT db1.dbo.products.sku
      FROM db1.dbo.products
      LEFT JOIN db2.dbo.item ON db1.dbo.products.sku = db2.dbo.item.itemlookupcode
      WHERE db2.dbo.item.itemlookupcode IS NULL)

I am getting an invalid syntax error at ")"
I can't see what is wrong... please help.

fullbuggAsked:
Who is Participating?
 
8080_DiverConnect With a Mentor Commented:
Try reformatting your query:
UPDATE P  
SET active = '0'
FROM db1.dbo.products P
LEFT JOIN db2.dbo.item 
ON db1.dbo.products.sku = db2.dbo.item.itemlookupcode
WHERE db2.dbo.item.itemlookupcode IS NULL;

Open in new window

0
 
udaya kumar laligondlaConnect With a Mentor Technical LeadCommented:
replace       WHERE db2.dbo.item.itemlookupcode IS NULL)
with
      WHERE db2.dbo.item.itemlookupcode IS NULL) TableName
0
 
fullbuggAuthor Commented:
8080_Diver ... Thanks so much... That did the trick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.