数据库里有2个表t1和t2,存储内容如下:表t1:
dm(代码) xm(姓名)
101 张三
102 李四
103 王五表t2:
dm(代码) nl(年龄)
101 aaa.16
102 aaa.17
103 aaa.18我现在想实现的就是将t2表里aaa字段分别替换成t1表里对应的姓名,结果图如下:
dm(代码) nl(年龄)
101 张三.16
102 李四.17
103 王五.18我用以下语句实现提示“子查询返回的值多于一个”,语句如下:
update t2
set nl=replace(nl,'aaa',(select xm from t1 b where b.dm=dm))请高手指教!谢谢!
dm(代码) xm(姓名)
101 张三
102 李四
103 王五表t2:
dm(代码) nl(年龄)
101 aaa.16
102 aaa.17
103 aaa.18我现在想实现的就是将t2表里aaa字段分别替换成t1表里对应的姓名,结果图如下:
dm(代码) nl(年龄)
101 张三.16
102 李四.17
103 王五.18我用以下语句实现提示“子查询返回的值多于一个”,语句如下:
update t2
set nl=replace(nl,'aaa',(select xm from t1 b where b.dm=dm))请高手指教!谢谢!
n1 = REPLACE(n1,'aaa',(SELECT xm FROM t1 WHERE t1.dm = t2.dm));
set nl=replace(t2.nl,'aaa',t1.xm)
from t1
where t1.dm=t2.dm
update t2 set nl=a.xm+substring(nl,charindex(nl,'.'),3) from t1 a, t2 b where a.dm=b.dm