if exists(select 1 from Table1 where A=0)
begin
update Table1
set B=B+1
from Table1
where A=0
end
else
begin
insert into Table1(A,B)
select 0,0
end

解决方案 »

  1.   

    if (select count(1) from table1 where a=0)>0
    update table1 set b=b+1 where a=0
    else
    insert table1 values(0,0)
      

  2.   

    if exists(select 1 from [Table1] where A=0)
    update [Table1] set B=B+1 where A=0
    else
    insert [Table1](A,B) select 0,0
      

  3.   

    ---A=0的记录的纪录存在时,执行存储过程后的结果create table table1(a int,b int)
    insert table1 select 0,1create proc p1
    as
    if (select count(1) from table1 where a=0)>0
    update table1 set b=b+1 where a=0
    else
    insert table1 values(0,0) 
    exec p1 
    select * from table1---A=0的记录的纪录不存在时,执行存储过程后的结果delete from table1exec p1 
    select * from table1
    drop table table1
    drop proc p1
      

  4.   

    用exists效率会好些!  同意啊~
      

  5.   

    假设你的数据列的数据类型都为INT
    if exists(select * from table1 where a=0)
    begin
    update table1 set b=b+1
    end
    else
    begin
    insert table1(a,b) values(0,0)
    end
      

  6.   

    大家有时间的话,帮我看看这个帖。
    http://community.csdn.net/Expert/TopicView3.asp?id=5488358