create table tableA(sStr int) insert into tableA select 2 union all select 3 godeclare @str int set @str=4 if((select count(1) from tableA where sStr = @str)<=0) select top 1 sStr = '0' from tableA else select sStr from tableA where sStr = @str--drop table tableA
insert into tableA select 2
union all select 3
godeclare @str int
set @str=4
if((select count(1) from tableA where sStr = @str)<=0)
select top 1 sStr = '0' from tableA
else
select sStr from tableA where sStr = @str--drop table tableA