一条联表更新的SQL语句

zqfleaf 2003-12-11 10:49:11
SQL Server可以这个写
update tp_prolo set f_firsstock=b.f_quantity

from tp_prolo a , tp_recordrow b

where a.vc_pandianid=b.vc_pandianid and a.vc_locatecode=b.vc_locatecode
and a.vc_productid=b.vc_productid and b.vc_pdrowid='000000000001'

请问DB2里面怎么写???

有一种比较笨的方法:
update tp_prolo a set a.f_firststock=
case when
(select b.f_quantity from tp_recordrow b
where a.vc_pandianid=b.vc_pandianid
and a.vc_locatecode=b.vc_locatecode
and a.vc_productid=b.vc_productid and
b.vc_pdrowid='000000000001')
is null
then a.f_firststock
else
(select b.f_quantity from tp_recordrow b
where a.vc_pandianid=b.vc_pandianid
and a.vc_locatecode=b.vc_locatecode
and a.vc_productid=b.vc_productid and
b.vc_pdrowid='000000000001')
end
不知哪位大侠有更简洁的方法?
...全文
51 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianshisuo 2003-12-31
  • 打赏
  • 举报
回复
可以稍简化一下:

update tp_prolo a set a.f_firststock=
coalesce((select b.f_quantity from tp_recordrow b
where a.vc_pandianid=b.vc_pandianid
and a.vc_locatecode=b.vc_locatecode
and a.vc_productid=b.vc_productid and
b.vc_pdrowid='000000000001')
,a.f_firststock)
sbks 2003-12-30
  • 打赏
  • 举报
回复
学习
zqfleaf 2003-12-30
  • 打赏
  • 举报
回复

5,889

社区成员

发帖
与我相关
我的任务
社区描述
IBM DB2 是美国IBM公司开发的一套关系型数据库管理系统,它主要的运行环境为UNIX(包括IBM自家的AIX)、Linux、IBM i(旧称OS/400)、z/OS,以及Windows服务器版本
社区管理员
  • DB2
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧