Solved

updating one table in sql  via a query referencing two tables

Posted on 2011-03-01
2
339 Views
Last Modified: 2012-05-11

i have the following query:


select a.opp_id, a.no_id, a.AddDate, a.contract, a.TerritoryName,
b.opp_id, b.reference_id, b.flag, b.actdate
from table1  a, table2  b where a.TerritoryName in
(
'21111',
'22222',
'23333',)
and a.AddDate >= '2009-11-01 15:00:55.000'
and a.Opp_ID = b.opp_id


I want to update the b.actdate = '2011-04-05 01:00:55.000'
in the query results above.


would it be

--update table2
set actdate = '2011-04-05 01:00:55.000'
where (select a.opp_id, a.no_id, a.AddDate, a.contract, a.TerritoryName,
b.opp_id, b.reference_id, b.flag, b.actdate
from table1  a, table2  b where a.TerritoryName in
(
'21111',
'22222',
'23333',)
and a.AddDate >= '2009-11-01 15:00:55.000'
and a.Opp_ID = b.opp_id

not sure I have update syntax right



update
0
Comment
Question by:Amanda Walshaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 35014142
UPDATE b
set actdate = '2011-04-05 01:00:55.000'
from table2  b inner join table1  a on a.Opp_ID = b.opp_id
where a.TerritoryName in 
(
'21111',
'22222',
'23333')
and a.AddDate >= '2009-11-01 15:00:55.000'

Open in new window

0
 

Author Closing Comment

by:Amanda Walshaw
ID: 35014532
yes exact
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question