如何将以下查询转换为sqlserver 2008r2中的merge语句 [英] how to convert the below query into merge statement in sqlserver 2008r2
问题描述
以下代码我得到重复的值,我不想要重复这个我想我需要把它改成Merge声明。
可以任何机构帮助我如何将以下代码更改为合并声明
插入 进入 [dbo]。[cmscpt_new]([Code],[Description ],[InputOn]
,[InputBy],[CptReview],[AddedbyApplication],[Status])
select [code],[description],getdate(),' 101',' n',' VAN',' Active'
FROM [dbo]。[cpt_load_2013]
- 其中current_update_indicator<>'D'和修饰符= '00'
其中 current_update_indicator<> ' D' 或 current_update_indicator null 或修饰符= ' 00' 或
修饰符 null
update a
set a。[description] = b。[description]
来自 [cmscpt_new] a,[cpt_load_2013] b
其中 a。[代码] = b。[代码]
Hi , 这篇关于如何将以下查询转换为sqlserver 2008r2中的merge语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
with the below code i am getting duplicate values , i don''t want duplicates for this i am thinking i need to change it into Merge statement.
can any body help me how to change the below code into merge statement
insert into [dbo].[cmscpt_new] ([Code],[Description] ,[InputOn]
, [InputBy] ,[CptReview],[AddedbyApplication],[Status])
select [code],[description],getdate(),'101','n','VAN','Active'
FROM [dbo].[cpt_load_2013]
-- where current_update_indicator <>'D' and Modifier ='00'
where current_update_indicator <>'D' or current_update_indicator is null or Modifier ='00' or
Modifier is null
update a
set a.[description]= b.[description]
from [cmscpt_new] a, [cpt_load_2013] b
where a.[Code]=b.[Code]
Take a look at SQL SERVER – 2008 – Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE[^]