CREATE PROCEDURE dt_sys_fukuan 
@jifen numeric(10,2) ,@sid int,@info varchar 
AS 
select @jifen=Integrations,@sid=shouid,@info=cause from mm_account where AddDate <= getdate() 循环读取上面sql语句信息,进行循环修改和插入 while(@@fetch_status=0) 
BEGIN 
  update china_user set Integration=Integration+@jifen where id=@sid 
  insert into china_account(userid,Integrations,symbol,cause) values(@sid,@jifen,1,@info) END GO这个是我写的,不正确。

解决方案 »

  1.   

    两条语句:UPDATE A SET A.Integration=A.Integration+B.Integration FROM china_user A INNER JOIN mm_account B ON a.id=b.shouid WHERE AddDate<=GETDATE()
    INSERT  china_account(userid,Integrations,symbol,cause) SELECT shouid,Integrations,1,cause FROM mm_account WHERE AddDate<=GETDATE()
      

  2.   

    CREATE PROCEDURE dt_sys_fukuan 
    @jifen numeric(10,2) ,@sid int,@info varchar(500)
    AS 
    set nocount on
    declare c cursor for
    select Integrations,shouid,cause from mm_account where AddDate <= getdate()
    open c
    fetch next from c into @jifen,@sid,@info
    while(@@fetch_status=0) 
    BEGIN 
      update china_user set Integration=Integration+@jifen where id=@sid 
      insert into china_account(userid,Integrations,symbol,cause) values(@sid,@jifen,1,@info) 
      fetch next from c into @jifen,@sid,@info
    END 
    close c
    deallocate c
    set nocount off
    GO