一个游标例子:
Declare @personid as varchar(50)Declare personid_cursor cursor for select name from f_person
 
open personid_cursorfetch next from personid_cursor into @personidwhile @@fetch_status=0
begin
       declare @name varchar(50)
       select @name=personid from f_person where personid=@personid  
       update f_admin set admin=@name where admin=@personid       fetch next from  personid_cursor into @personid
endclose personid_cursordeallocate personid_cursor

解决方案 »

  1.   

    Declare @employeeid as intDeclare employeeid_cursor cursor for select employeeid from employees
     
    open personid_cursorfetch employeeid_cursor into @employeeidwhile @@fetch_status=0
    begin
           declare @Lastname varchar(50)
           ......定义所有字段对应的变量
           select @Lastname=Lastname,... from employees where employeeid=@employeeid  
           fetch next from  employeeid_cursor into @employeeid
    endclose employeeid_cursordeallocate employeeid_cursor