想知道是否有人可以朝着正确的方向刺我。我目前有这个脚本(Advantage Arc),但是我想将第二个select语句与Update语句合并在一起,所以最后得到第一个Select语句,然后是Update语句。我知道这应该是可能的,但是我做得不太对:
SELECT
e.ident
, LEFT(othersys_id, 16) AS sysid
INTO #epilink
FROM epidata e JOIN trainee t ON e.ident = t.ident
WHERE
fundorg = 'PRV1'
;
SELECT
e.ident
, et.maptopicsethniccode
INTO #tmp
FROM #epilink e
JOIN [.._control\pics.add]._trainee t ON e.sysid = t.traineeid
JOIN [.._control\pics.add]._ethnicity et ON et.maytasethniccode = t.ethnicgroup
WHERE
t.ethnicgroup IS NOT NULL
;
UPDATE
epidata
SET
ethcode = (
SELECT
et.maptopicsethniccode
FROM #epilink e
JOIN [.._control\pics.add]._trainee t ON e.sysid = t.traineeid
JOIN [.._control\pics.add]._ethnicity et ON et.maytasethniccode = t.ethnicgroup
WHERE
t.ethnicgroup IS NOT NULL
);
答案 0 :(得分:1)
我认为您需要的是对多个表进行更新,可以使用以下语法完成:
UPDATE
dat
SET
ethcode = et.maptopicsethniccode
FROM epidata dat
JOIN #epilink e ON e.ident = dat.ident
JOIN [.._control\pics.add]._trainee t ON e.sysid = t.traineeid
JOIN [.._control\pics.add]._ethnicity et ON et.maytasethniccode = t.ethnicgroup
WHERE
t.ethnicgroup IS NOT NULL
;
我在update子句的顶部指定了要更新的表的别名,并将所有内容从子选择中拉到了主语句中。
您可以在文档中看到有关ADS UPDATE语句示例的语法:
http://devzone.advantagedatabase.com/dz/webhelp/Advantage12/master_update.htm
创建表a(id整数,val整数)
创建表b(id整数,val整数)
插入值(1,10)
插入b值(1,20)
插入b值(1,30)
更新一个
SET a.val = b.Val
在a.id = b.id上从a内部联接b