if exists(select 1 from [table] where [user_id]=9999)
  update..
else
  insert..
或:update [table] set..... where [user_id]=9999if @@rowcount=0
  insert...

解决方案 »

  1.   

    推荐用这种
    update [table] set..... where [user_id]=9999if @@rowcount=0
      insert...
      

  2.   

    可以不判断,直接更新
    update 表 set ... where user_id=9999
    if @@rowcount=0  --如果更新记录为0条,则说明不存在,执行插入
      insert into 表() values()
      

  3.   

    “update [table] set..... where [user_id]=9999if @@rowcount=0
      insert...

    HEI,HEI!!
    又学了一招!!!
    UP,UP,UP!!!
      

  4.   

    begin
    if exists(select 1 from tablename where id=9999)
       update tablename set ......
    else
       insert tablename ......
    end
      

  5.   

    同意 pengdali(大力 V3.0)