I've just tried it in Oracle.
cloud2001(卷云溶月)'s suggestion will assign NULL to record(cat='b' && type=1) as in the result shown below:
SQL> select * from tableA;
C TYPE VAL
- ---------- ----------
a 1 1000
a 2 110
b 1
b 2 201
c 1 2020
c 2 421
6 rows selected.
But thank cloud2001(卷云溶月) anyway.
As for cyt(千山万水走遍)'s suggestion, I couldn't find out what the correct syntax should be. When I tried the following:
UPDATE tableA A
SET A.val= (
SELECT DECODE(A.type,1,B.val1,2,B.val2)
FROM tableA A, tableB B
WHERE B.cat=A.cat)
Oracle complained, "single-row subquery returns more than one row".
Any tips, cyt(千山万水走遍) ?
I'll start try yangn(Raymond)'s suggestion in MS SQL Server. (to be continue)
cloud2001(卷云溶月)'s suggestion will assign NULL to record(cat='b' && type=1) as in the result shown below:
SQL> select * from tableA;
C TYPE VAL
- ---------- ----------
a 1 1000
a 2 110
b 1
b 2 201
c 1 2020
c 2 421
6 rows selected.
But thank cloud2001(卷云溶月) anyway.
As for cyt(千山万水走遍)'s suggestion, I couldn't find out what the correct syntax should be. When I tried the following:
UPDATE tableA A
SET A.val= (
SELECT DECODE(A.type,1,B.val1,2,B.val2)
FROM tableA A, tableB B
WHERE B.cat=A.cat)
Oracle complained, "single-row subquery returns more than one row".
Any tips, cyt(千山万水走遍) ?
I'll start try yangn(Raymond)'s suggestion in MS SQL Server. (to be continue)