IF EXISTS (SELECT 1 FROM 表名 WHERE 条件)
UPDATE 表名 SET 字段=值 WHERE 条件
ELSE
INSERT INTO 表名(字段) VALUES(值)

真实使用举例:

if exists(select 1 from [UserRules] where UserID=@UserID)
update [UserRules] set [AttendanceRulesID]=@AttendanceRulesID where UserID=@UserID
else
insert into [UserRules] (UserID,AttendanceRulesID) Values(@UserID,@AttendanceRulesID)
05-11 13:57