declare @f1 varchar(10),@f2 varchar(100)DECLARE authors_cursor CURSOR FOR 
SELECT f1,f2 from table1OPEN authors_cursor
FETCH NEXT FROM authors_cursor into @f1,@f2WHILE @@FETCH_STATUS = 0
BEGIN
   exec ('update set total='+@f2+' from pubs..jobs where field0='+@f1)
   FETCH NEXT FROM authors_cursor into @f1,@f2
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor

解决方案 »

  1.   

    更正:
    declare @f1 varchar(10),@f2 varchar(100)DECLARE authors_cursor CURSOR FOR 
    SELECT f1,f2 from table1OPEN authors_cursor
    FETCH NEXT FROM authors_cursor into @f1,@f2WHILE @@FETCH_STATUS = 0
    BEGIN
       exec ('update set total='+@f2+' from table2 where field0='+@f1)
       FETCH NEXT FROM authors_cursor into @f1,@f2
    ENDCLOSE authors_cursor
    DEALLOCATE authors_cursor
      

  2.   

    create proc proc_formula 
    as
    begin
      declare @a varchar(20)
      declare @s varchar(256)
      declare @str varchar(2560)
      declare cur_x cursor for select f1, f2 from table1 
      open cur_x
      fetch next from cur_x
      into @a,@s
      while @@fetch_status = 0
      begin
        select @str ='update table2 set total= ' + @s + '  where f1 = ''' +@a +''''
        print (@str)
        fetch next from cur_x
        into @a,@s
      end
      
      close cur_x
      deallocate cur_x  
    end
      

  3.   

    create proc proc_formula 
    as
    begin
      declare @a varchar(20)
      declare @s varchar(256)
      declare @str varchar(2560)
      declare cur_x cursor for select f1, f2 from table1 
      open cur_x
      fetch next from cur_x
      into @a,@s
      while @@fetch_status = 0
      begin
        select @str ='update table2 set total= ' + @s + '  where f1 = ''' +@a +''''
        print (@str)
        fetch next from cur_x
        into @a,@s
      end
      
      close cur_x
      deallocate cur_x  
    end
      

  4.   

    create proc proc_formula 
    as
    begin
      declare @a varchar(20)
      declare @s varchar(256)
      declare @str varchar(2560)
      declare cur_x cursor for select f1, f2 from table1 
      open cur_x
      fetch next from cur_x
      into @a,@s
      while @@fetch_status = 0
      begin
        select @str ='update table2 set total= ' + @s + '  where f1 = ''' +@a +''''
        exec (@str)
        fetch next from cur_x
        into @a,@s
      end
      
      close cur_x
      deallocate cur_x  
    end
      

  5.   

    create proc proc_formula 
    as
    begin
      declare @a varchar(20)
      declare @s varchar(256)
      declare @str varchar(2560)
      declare cur_x cursor for select f1, f2 from table1 
      open cur_x
      fetch next from cur_x
      into @a,@s
      while @@fetch_status = 0
      begin
        select @str ='update table2 set total= ' + @s + '  where field0 = ''' +@a +''''
        exec (@str)
        fetch next from cur_x
        into @a,@s
      end
      
      close cur_x
      deallocate cur_x  
    endgoproc_formula
    go