| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4515 人关注过本帖
标题:update 为什么要 where exist ,不然会更新失败
只看楼主 加入收藏
StudentYu
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-9-26
收藏
 问题点数:0 回复次数:0 
update 为什么要 where exist ,不然会更新失败
如:创建临时表:create table temptable123 as  select  t3.fentryid fentryid,t0.FDeclarationNo FDECLARELISTNO_LT,t1.FDeclareItemNo FDECLARENO_LT,t0.FDECLARATIONDATE FDECLARATIONDATE_LT      
from LT_T_IEP_ImportDeclare t0
   inner join LT_T_IEP_ImportDeclEntry t1 on t0.fid = t1.fid
   inner join LT_T_IEP_ImportDecl_LK t2  on t1.fentryid = t2.fentryid and t2.fstablename = 'T_PUR_MRBENTRY'
   inner join T_PUR_MRBENTRY t3 on t2.fsid = t3.FEntryID
   inner join t_pur_mrb t4 on t3.fid = t4.fid
   where t0.FDOCUMENTSTATUS = 'C'
跟新
   update T_PUR_MRBENTRY
      set (FDECLARELISTNO_LT,FDECLARENO_LT,FDECLARATIONDATE_LT)=  
  (select FDECLARELISTNO_LT,FDECLARENO_LT,FDECLARATIONDATE_LT      
   from  temptable123
            where T_PUR_MRBENTRY.fentryid = temptable123.fentryid)
where exists(select 1 from temptable123 where T_PUR_MRBENTRY.fentryid = temptable123.fentryid)  

drop table temptable123
这种方式的更新的区别:
update t_bd_MaterialPurchase
   set (fdefaultvendorid) =
       (select fdefaultvendorid
          from (select t0.fentryid fentryid, t3.fsupplierid fdefaultvendorid
                  from t_bd_MaterialPurchase t0
                 inner join T_BD_MATERIAL t1  on t0.fmaterialid = t1.fmaterialid
                 inner join t_BD_Supplier t2 on t1.fmasterid = t2.fmasterid
                 inner join t_BD_Supplier t3 on t1.fuseorgid = t3.fuseorgid
                 inner join T_BD_MATERIAL t4 on t4.fmasterid = t1.fmasterid
                 ) t
         where t_bd_MaterialPurchase.fentryid = t.fentryid)
搜索更多相关主题的帖子: update create where inner 
2014-09-26 11:13
快速回复:update 为什么要 where exist ,不然会更新失败
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052286 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved