This SQL statement example is very close to what I think I need…
update table1 set value1 = x.value1 from
(select value1, code from table2
where code = something) as x
However, what I need to do is change the “something” in the above example to a value from the row that is being updated.
For example, I tried this but it didn’t work:
update table1 A set value1 = x.value1 from
(select value1, code from table2
where code = A.something) as x
This is a one time operation to update an existing table and I’m not really looking for high performance way to do this. Any solution that gets the task done is good enough.
Edit for clarification
I am using Microsoft SQL Server 6.5.
Edit
I’ve since had several smart people tell me that many of the answers posted here should have worked. My specific sql statement was way more convoluted than the pseudo sql I used in my example. For some reason the answers I tried (most of them) did not work. The same smart people couldn’t figure out why they didn’t work either.
The answer I selected did work for me. Future answer seekers should probably look at several other answers below to help resolve their own questions, not just the one that solved my issue.
Have you tried something like this :-