IT科技

如何在存储过程中实现插入更新数据

时间:2010-12-5 17:23:32  作者:应用开发   来源:应用开发  查看:  评论:0
内容摘要:复制Createprocsp_Insert_Student @Nochar(10), @Namevarchar(20), @Sexch

如何在存储过程中实现插入更新数据
复制Create proc sp_Insert_Student      @Nochar(10),何存      @Namevarchar(20),      @Sex char(2),      @Age int,      @rtn intoutput as declare     @tmpName varchar(20),      @tmpSex char(2),      @tmpAge int     if exists(select * from Student whereNo=@No)          begin             select @tmpName=Name,@tmpSex=Sex,@tmpAge=Age from Student whereNo=@No             if ((@tmpName=@Name) and (@tmpSex=@Sex) and (@tmpAge=@Age))                  begin                     set @rtn=0   --有相同的数据,直接返回值                 end             else                 begin                     update Student setName=@Name,储过程中插入Sex=@Sex,Age=@Age whereNo=@No                     set @rtn=2   --有主键相同的b2b供应网数据,进行更新处理                 end         end     else         begin             insertinto Student values(@No,实现数据@Name,@Sex,@Age)              set @rtn=1    --没有相同的服务器租用数据,更新进行插入处理         end 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.云服务器提供商
copyright © 2025 powered by 编程之道  滇ICP备2023006006号-34sitemap