• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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.

0
fullbugg
Asked:
fullbugg
2 Solutions
 
8080_DiverCommented:
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 laligondlaTechnical 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now