动态SQL未更新所有内容后更新语句

时间:2016-03-16 20:26:07

标签: sql sql-server join

我的陈述是:

set @cmd = '
exec pr_sys_drop_object ''ztb_staging_Demand_prep''

select *
into ztb_staging_Demand_prep                                         
from ndcaspsqlp01.[source table] A

' 
--print @cmd
exec(@cmd)

;Update A
set A.Material_CD = B.Planning_Material_CD
from ztb_staging_Demand_prep A
inner join ztb_planning_material_mapping b on A.Material_Cd = B.material_CD

但是,在表ztb_staging_Demand_prep中搜索应该在更新中映射的材料,material_cd,一些material_cd仍然存在。我知道这个,因为如果我只是跑:

Update A
    set A.Material_CD = B.Planning_Material_CD
    from ztb_staging_Demand_prep A
    inner join ztb_planning_material_mapping b on A.Material_Cd = B.material_CD

之后,那些应该更新的材料,不再出现,这是正确的。

我知道SQL是同步的,但为什么/如何不更新模型?是否有设置,以便更新仅在exec()完成后发生

我在本节之前定义了需要在该语句之后访问的变量

0 个答案:

没有答案