需求如下:
  ado连接数据库,需要读的时候读3个值,写的时候写3个值进去,如果数据库内无值就新写一条记录进去,有值则把相应需要修改的值修改掉,急,如果对我写的需求有疑问的,我会针对性的再做详细说明,谢谢各位大虾指点。

解决方案 »

  1.   

    create proc sp_test( @a int,@b int,@c int)
    as 
    declare
      @count int;
    begin
      select @count=count(*) from table1 where ..;
      if @count=0 
        insert into table1 values(@a,@b,@c);
      else
        update table1 set a=@a,b=@b,c=@c where ...
    end;
      

  2.   

    主要是不知道sql语句那里@count=count(*)怎么取
      

  3.   

    不规范吗?很简单的一个存储过程判断select @count=count(*) from table1 where ..;记录是否存在@count=0不存在执行insert 语句,@count>0就存在 执行update语句,where 条件的你自己填充
      

  4.   

    select @count=count(*) from table1 where a=@a;
    //查找字段a与@a相同的记录count(*)返回行数,0表示没有找到
      

  5.   

    //怎么感觉你一直在问没有动手啊declare
    @count int;
    begin
    ....
    end;
      

  6.   

    因为我之前针对单一需求已经做过了,只是以前没有写过通用的过程,对于函数的调用和sql语句的连接有疑问,读数据都好说,主要是取数据的时候觉得太麻烦了