楼主可是这意思?declare @tb table(id int primary key, value varchar(30)) declare @id int=10,@value varchar(30)='aaaa'
--1 直接 Insert into @tb(id,value) Select @id,@value where not exists(select * from @tb b where b.id=@id ) Select * from @tb Delete from @tb where id=@id --2 选择性 if not exists (select * from @tb b where b.id=@id ) Begin Insert into @tb(id,value) Select @id,@value end if exists (select * from @tb b where b.id=@id ) Begin Delete from @tb where id=@id end
EXEC SP_EXECUTESQL N'STRSQL'
declare @id int=10,@value varchar(30)='aaaa'
--1 直接
Insert into @tb(id,value)
Select @id,@value
where not exists(select * from @tb b where b.id=@id )
Select * from @tb Delete from @tb where id=@id
--2 选择性
if not exists (select * from @tb b where b.id=@id )
Begin
Insert into @tb(id,value)
Select @id,@value
end
if exists (select * from @tb b where b.id=@id )
Begin
Delete from @tb where id=@id
end