下面的UPDATE语句错在哪里,如何改?
下面的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