I have the following records generated through some sql joins.
ID SYSTEM CODE
1 W A
2 W NULL
3 W NULL
4 W B
5 U X
In the above generated records I need to update all the records CODE as 'X' since the SYSTEM U has X in it. Please note this CODE which is I'm updating is from some table say CODES_TABLE. How do I do that through stored procedure? DO I have to create some temp table to hold these vales somewhere? Thanks in advance
Is this what you want?
update t
set code = (select t2.code from t t2 where t2.system = 'U')
where t2.system <> 'U';
EDIT:
Or, for a query, just use analytic functions:
select t.*, max(case when system = 'U' then code end) over () as u_code
from t;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.