SQL判断是否存在该数据 有则更新,没有则插入


Update  dbo.PartOpr
         Set  字段=值
-- 存在記錄才更新
Where  OperationDesc=@OperationDesc 
     and  TopVersion=@TopVersion 
     and  DrawNum=@DrawNum  
     and  TopPartNum=@TopPartNum 
     and  [Version]=@Version
 
 
Insert  into  dbo.PartOpr(字段)
     Select 
             字段
         -- 不存在記錄才插入
         Where  Not  exists( select  from  dbo.PartOpr               
                             Where  OperationDesc=@OperationDesc 
                                 and  TopVersion=@TopVersion 
                                 and  DrawNum=@DrawNum  
                                 and  TopPartNum=@TopPartNum 
                                 and  [Version]=@Version
                     )


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM