如果物料编码只是A,要替換成B,用下面的就可以了,
declare @i varchar(100)
declare @j varchar(20)
declare c1 cursor scroll for 
  select [name] from sysobjects where [id] in (select [id] from syscolumns where [name]='物料编码')
open c1
fetch first from c1 into @j
while @@fetch_status=0
    begin
     set @i= 'update  '+@j+'  set  物料编码 ='+ char(39)+'B'+char(39)+'   where  物料编码='+char(39)+'A'+char(39)
      fetch next from c1 into @j
    end
close c1
deallocate c1
exec (@i)

解决方案 »

  1.   

    修改下,可以把類如物料编码xxxAxxxx中的A都替換成B,變成xxxBxxxx
    set @i='select replace(物料编码,'+char(39)+'A'+char(39)+','+char(39)+'B'+char(39)+') from '+@j+ 'where 物料编码 like '+char(39)+'%A%'+char(39)
      

  2.   

    不好意思,貌似好像連where都可以省掉
    set @i='select replace(物料编码,'+char(39)+'A'+char(39)+','+char(39)+'B'+char(39)+') from '+@j
      

  3.   

    Sorry....真該打~~~~~~不知道這樣可以不?試試吧...Set @i='update '+@j+' set '+@j+'.物料编号=C.new from (select 物料编号,replace(物料编号,'+char(39)+'A'+char(39)+','+char(39)+'B'+char(39)+') as new from '+@j+') C   where '+@j+'.物料编号=C.物料编号'