SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update statement with joins
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 07/18/2014 :  05:17:06  Show Profile  Reply with Quote
I've got this select statement

SELECT Replies.*, JobDetails.*, Subscribers.*
FROM tblSmsReplies Replies
LEFT JOIN tblJobDetails JobDetails ON Replies.JobDetailId = JobDetails.JobDetailId
LEFT JOIN tblSubscribers Subscribers ON JobDetails.SubscriberId = Subscribers.SubscriberId
WHERE Replies.SmsContent = 'stop'

How can I make that an update statement, to update all those rows to Subscribers.StatusId = 2

Thanks

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 07/18/2014 :  05:27:43  Show Profile  Visit SwePeso's Homepage  Reply with Quote
-- Select
SELECT		dbo.Replies.*,
		dbo.JobDetails.*,
		dbo.Subscribers.*
FROM		dbo.tblSmsReplies AS Replies
LEFT JOIN	dbo.tblJobDetails AS JobDetails ON JobDetails.JobDetailId = Replies.JobDetailId
LEFT JOIN	dbo.tblSubscribers AS Subscribers ON Subscribers.SubscriberId = JobDetails.SubscriberId
WHERE		Replies.SmsContent = 'stop';

-- Update
UPDATE		Subscribers
SET		Subscribers.StatusId = 2
FROM		dbo.tblSmsReplies AS Replies
LEFT JOIN	dbo.tblJobDetails AS JobDetails ON JobDetails.JobDetailId = Replies.JobDetailId
LEFT JOIN	dbo.tblSubscribers AS Subscribers ON Subscribers.SubscriberId = JobDetails.SubscriberId
WHERE		Replies.SmsContent = 'stop';



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000