如何将以下查询转换为sqlserver 2008r2中的merge语句 [英] how to convert the below query into merge statement in sqlserver 2008r2

查看:122
本文介绍了如何将以下查询转换为sqlserver 2008r2中的merge语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下代码我得到重复的值,我不想要重复这个我想我需要把它改成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。[代码]

解决方案

看看 SQL SERVER - 2008 - 合并语句简介 - INSERT,UPDATE,DELETE的一个语句 [ ^ ]


Hi ,

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[^]


这篇关于如何将以下查询转换为sqlserver 2008r2中的merge语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆