create PROCEDURE [dbo].[Pr_inportEasy_updateORinsert] @P1 varchar(20), @P2 varchar(20), @p3 int AS --创建 if EXISTS(select * from inportEasy WHERE inportbName = @P1 and typeI = @P2) begin update inportEasy set quantity = quantity + @p3 WHERE inportbName = @P1 and typeI = @P2 --如果存在就更新 end else begin insert into dbo.inportEasy (inportbName,typeI,quantity) values (@P1,@P2,@p3) --如果不存在就插入 end
执行存储过程:
execute Pr_inportEasy_updateORinsert 'I5 2430', 'CPU', 3
参考自:http://hi.baidu.com/tidy0608/item/ff930fe2436f2601560f1dd9