//merge into 语法例
/*
* merge into
* dtjc.t_gdxm new_gdxm
using tdly.t_gdxm temp_gdxm
on (new_gdxm.gd_guid = temp_gdxm.gd_guid)
when matched then
update set
new_gdxm.zd_guid=temp_gdxm.zd_guid,
new_gdxm.xzq_dm=temp_gdxm.xzq_dm,
new_gdxm.td_yt=temp_gdxm.td_yt
when not matched then
insert values(
temp_gdxm.zd_guid,
temp_gdxm.xzq_dm,
temp_gdxm.td_yt
)
*/
/* 修正为空的字段也更新的问题做了处理
* 参照下例
* merge into
student_new new_gdxm
using student temp_gdxm
on (new_gdxm.name = temp_gdxm.name)
when matched then
-- 当字段为空的时候不更新,获取数据时,有时好多字段为空,字段值获取不稳定
-- 字段为空的时候保持原来表中的值
update set adress=case
when temp_gdxm.adress is not null
then temp_gdxm.adress else new_gdxm.adress end,
adress1=case
when temp_gdxm.adress1 is not null
then temp_gdxm.adress1 else new_gdxm.adress1 end
when not matched then
insert values(
temp_gdxm.name,
temp_gdxm.adress,
temp_gdxm.adress1)*/
merge into 用法
最新推荐文章于 2024-05-14 17:33:22 发布