Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update query selection criteria

Status
Not open for further replies.

jcf27

IS-IT--Management
Aug 24, 2002
21
0
0
US
The following update query runs OK, except that it clears out fields corresponding to rows not meeting the criteria. How can I make it update only the selected rows and leave others as they are?

Thanks in advance.

J.

update address fa
set address = (select psc.value
FROM sec_code p
WHERE (fa.name = p.name)
 
update address fa
set address = (select psc.value
FROM sec_code p
WHERE (fa.name = p.name)
WHERE name in (select name from sec_code)


should do it, but it may well be slower I tried to remain child-like, all I acheived was childish.
 
If your update modifies a large percentage of your data you could try:

update address fa
set address = COALESCE((select psc.value
FROM sec_code p
WHERE (fa.name = p.name), address)

To DBMS should be smart enough to update only those rows where the address changes.

Dieter
 
Try this.

UPDATE Address
SET address = p.value
FROM Address fa
INNER JOIN sec_code p
ON fa.name = p.name
WHERE fa.Address<>p.Value Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top