首页 > 代码库 > 游标循环读取数据,更改数据

游标循环读取数据,更改数据

declare @tab_name varchar(100),@col_name varchar(100),@newResult varchar(max),@sql varchar(max)
declare curTab_setData cursor fast_forward   
for select * from Table_1  where tab_name<>‘[dbo].[STEM_Log]‘
    open curTab_setData   
    fetch next from curTab_setData into @tab_name,@col_name
    while @@FETCH_STATUS=0   
    begin 
        --set @sql=‘select substring(‘+@col_name+‘,1,charindex(‘‘<div style=‘‘,‘+@col_name+‘)-1),‘+@col_name+‘ colname from ‘+@tab_name
        --+‘ where‘+@col_name+‘ like‘‘%div style%‘‘‘
        ----print @sql
        --exec(@sql)
         set @sql=‘update  ‘+@tab_name+‘set ‘+@col_name+‘= substring(‘+@col_name+‘,1,charindex(‘‘<div style=‘‘,‘+@col_name+‘)-1) 
         where‘+@col_name+‘ like‘‘%div style%‘‘‘
        exec( @sql)
        fetch next from curTab_setData into @tab_name,@col_name   
    end  
    close curTab_setData    
    deallocate curTab_setData

游标循环读取数据,更改数据