下面的UPDATE语句错在哪里,如何改?

myperry 2006-07-21 09:56:46

下面的UPDATE语句错在哪里,如何改?
下面的语句,如果全部执行,结果正常,
但是,如果只从update处往后执行会报错:
服务器: 消息 8154,级别 16,状态 1,行 1
表 'dtr_shch_n' 不明确。

原因应该是from后面两次引用了'dtr_shch_n' 表,请问如何改?

select a.user_date, a.id_shch_b, a.pnl1_zhr,
--update dtr_shch_n set pnl1_zhr =
isnull((d.pnl1_wch+d.pnl1_wf)-(case when (a.pnl1_wf-d.pnl1_wf)>0 then (a.pnl1_wf-d.pnl1_wf) else 0 end),0)
from dtr_shch_n a
left outer join dtr_shch_m1 b on a.id_shch_b=b.id_shch_b and a.gx_int=b.gx_int
left outer join dtr_shch_m1 c on b.id_shch_b=c.id_shch_b and b.gx_int_q=c.gx_int
left outer join dtr_shch_n d on a.id_shch_b=d.id_shch_b and a.page_no=d.page_no and b.gx_int_q=d.gx_int
where a.gx_int>1 and b.pnl_set='PNL' and c.pnl_set='PNL'
and a.pnl1_zhr <>isnull((d.pnl1_wch+d.pnl1_wf)-(case when (a.pnl1_wf-d.pnl1_wf)>0 then (a.pnl1_wf-d.pnl1_wf) else 0 end),0)
go
...全文
191 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ciwdba 2006-07-22
  • 打赏
  • 举报
回复
--------------------------------------------------------------
您好,我们是“2006中国杰出数据库工程师评选”活动组委会。
您的帖子已经被我们转载到本次评选官方网站的“专家在线答疑”区。
http://www.bestdba.cn/match_discussion.aspx

在那里,进入本次评选复选的90位数据库工程师将与您展开积极的互动。
一方面,他们会为您的问题提供满意的答案,
另一方面,也邀请您为他们投上宝贵的选票。

2006-7-8 ~ 2006-7-25日,每天我们将从当天参与"有奖投票"的网友
中抽取3名幸运者,赠送由IBM提供的精美礼品一份!

此外,您还可以在“专家在线答疑”区提出新的问题并参与讨论。

您的帖子位于:
http://www.bestdba.cn/match_discussion3.aspx?pointid=353&pointid2=1&pointid3=5&pcount=stc

非常感谢您对本次活动的支持!
--------------------------------------------------------------
LouisXIV 2006-07-21
  • 打赏
  • 举报
回复
--try

update a set pnl1_zhr =
isnull((d.pnl1_wch+d.pnl1_wf)-(case when (a.pnl1_wf-d.pnl1_wf)>0 then (a.pnl1_wf-d.pnl1_wf) else 0 end),0)
from dtr_shch_n a
left outer join dtr_shch_m1 b on a.id_shch_b=b.id_shch_b and a.gx_int=b.gx_int
left outer join dtr_shch_m1 c on b.id_shch_b=c.id_shch_b and b.gx_int_q=c.gx_int
left outer join dtr_shch_n d on a.id_shch_b=d.id_shch_b and a.page_no=d.page_no and b.gx_int_q=d.gx_int
where a.gx_int>1 and b.pnl_set='PNL' and c.pnl_set='PNL'
and a.pnl1_zhr <>isnull((d.pnl1_wch+d.pnl1_wf)-(case when (a.pnl1_wf-d.pnl1_wf)>0 then (a.pnl1_wf-d.pnl1_wf) else 0 end),0)

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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