SQL Server Update with left join and group by having

Posted by Marty Trenouth on Stack Overflow See other posts from Stack Overflow or by Marty Trenouth
Published on 2010-03-17T17:52:05Z Indexed on 2010/03/17 18:01 UTC
Read the original article Hit count: 308

Filed under:
|

I'm making an update to our datbase and would like to update rows that do not have existing items in another table. I can join the tables together, but am having trouble grouping the table to get a count of the number of rows

UPDATE dpt
SET dpt.active = 0 
FROM DEPARTMENT dpt
LEFT JOIN DOCUMENTS doc on dpt.ID = doc.DepartmentID
GROUP BY dpt.ID
HAVING COUNT(doc.ID) = 0

What should I be doing?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server