Declare @user_id numeric(9),@user_name varchar(10),@password varchar(15)
declare exportdata Cursor for select * from user_table where user_id=2
open exportdata
    fetch next from exportdata into @user_id,@user_name,@password 
while (@@fetch_status=0)
begin
    insert user_table1 values(@user_id,@user_name,@password)
    fetch next from exportdata into @user_id,@user_name,@password --这一句是新加的
end
CLOSE exportdata
DEALLOCATE exportdata

解决方案 »

  1.   

    insert user_tabl1(user_id,user_name,password)
    select user_id,user_name,password from user_table
    where user_id=2
      

  2.   

    Declare @user_id numeric(9),@user_name varchar(10),@password varchar(15)
    declare exportdata Cursor for select * from user_table where user_id=2
    open exportdata
        fetch next from exportdata into @user_id,@user_name,@password 
    while (@@fetch_status=0)
    begin
        insert user_table1 values(@user_id,@user_name,@password)
        fetch next from exportdata into @user_id,@user_name,@password --这一句是起到循环,否则形成死循环,就全是相同的记录了
    end
    CLOSE exportdata
    DEALLOCATE exportdata