您的位置:程序门 -> db2 -> 基础类



超难问题,征求高手解惑:请问update语句在db2中应该写?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


超难问题,征求高手解惑:请问update语句在db2中应该写?
发表于:2007-06-29 11:21:59 楼主
在sqlserver中,这样写是合法的:
update   a   set   a.name=b.name   from   table1   a,
(select   *   from   table2   where   idno1=1   and   idno2=2)   b
where   a.id=b.id
如果是在db2中,如何改写以上这句呢?因为别名为b的表本身就是一个查询语句所select出来的。

这个问题已经困扰我们多天,还是没有任何办法,因为涉及语句太多,全部使用游标要改动很大,请问有没有什么简便的方法可以解决这个难题呢?如果阁下能够帮忙我们解决,我们将不胜感激,谢谢大家!
发表于:2007-06-29 13:47:361楼 得分:0
難道沒有一位朋友懂嗎?
发表于:2007-06-29 17:13:202楼 得分:0
update   tabl   set   ***   from   ???
sqlserver里是这样写的?

update   table1   a   set   name=(select   name   from   table2   b   where   idno1=1   and   idno2=2   and   b.id=a.id   fetch   first   1   row   only)  
这个应该可以的吧?
发表于:2007-06-29 17:23:003楼 得分:0
把这个
select   name   from   table2   b   where   idno1=1   and   idno2=2
建立一个view
然后
update   ttt   a   set   name=(select   name   from   vib     where   a.employid=vib.employid   fetch   first   1   row   only)
update   table1   a   set   name=(select   name   from   view1   b   where   b.id=a.id   fetch   first   1   row   only)  
这样就没有错误了,fetch   first   1   row   only这个是必须有的。
发表于:2007-06-29 17:37:374楼 得分:0
建视图为了提高效率?
发表于:2007-07-02 15:26:025楼 得分:0
该回复于2007-12-29 16:26:41被管理员或版主删除


快速检索

最新资讯
热门点击