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 2005 Forums
 Transact-SQL (2005)
 update based on query

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2011-10-18 : 09:23:38
Hi

I need to do a update based on this query..


SELECT dbo.Roles.ID
FROM dbo.Login INNER JOIN
dbo.Roles ON dbo.Login.UID = dbo.Roles.UID INNER JOIN
dbo.Customer ON dbo.Login.CustID = dbo.Customer.CustID
WHERE (dbo.Customer.CustID = 2) AND (dbo.Roles.NodeID = 77) AND (dbo.Roles.IsActive = 0)


From this query I get a lot of ID's and they need to be used in the update statement which is supposed to look like this..


UPDATE dbo.Roles SET IsActive = 1 WHERE ID = (all my ID's from above)


How would I do that?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-18 : 09:35:24
[code]
SELECT dbo.Roles.ID
UPDATE dbo.Roles
SET IsActive = 1

FROM dbo.Login INNER JOIN
dbo.Roles ON dbo.Login.UID = dbo.Roles.UID INNER JOIN
dbo.Customer ON dbo.Login.CustID = dbo.Customer.CustID
WHERE (dbo.Customer.CustID = 2) AND (dbo.Roles.NodeID = 77) AND (dbo.Roles.IsActive = 0)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2011-10-18 : 09:40:50
Ahh, thanks!
Go to Top of Page
   

- Advertisement -