日期:2014-05-18  浏览次数:20429 次

大哥们帮个忙啊,谢谢(关于检索赋值)
原表是这样的:
id号     字段A     字段B
1           tttt       null
2           gggg       null
3           ffff         1
4           bbbb         1
5           hhhh         2

要得到的结果是:
id号     字段A     字段B
1           tttt       null
2           gggg       null
3           tttt         1
4           tttt         1
5           gggg         2

需求大致是:字段B为空的记录不处理。根据字段B里面的ID号,将字段A重新赋值成这个ID号对应的字段A里面的值。

我试过用嵌套查询更新,但提示“子查询返回的值多于一个。”。。可能用到游标麽?
恳请各位大侠帮忙。。
我是这么写的
update   table   set   字段A=(select   字段A   from   table   where   id=(select   字段B   from   table))

------解决方案--------------------
update tb
set a = t.a
from tb , tb a
where tb.b = a.id