日期:2014-05-17  浏览次数:20502 次

求助,批量更改列名
表列名如下:

5550087_C.abc 5550088_C.abc 5550088_D.abc 5550088_E.abc 等400余条

改成如下:

5550087C 5550088C 5550088D 5550088E

求语句

------解决方案--------------------
SQL code

declare @col varchar(15)
set @col='5550087_C.abc'
select left(@col,7)+substring(@col,9,1)

------解决方案--------------------
SQL code
declare @sql varchar(8000)
select 
  @sql=isnull(@sql+char(10),'')
  +'exec sp_rename ''['+a.name+'].['+b.name+']'', '''+replace(replace(b.name,'_',''),'.abc','')+'''' 
from 
  sysobjects a join syscolumns b on a.id=b.id 
where 
 a.type='U' and b.name like '%.abc'
exec (@sql)

------解决方案--------------------
探讨
引用:
SQL code
declare @sql varchar(8000)
select
@sql=isnull(@sql+char(10),'')
+'exec sp_rename ''['+a.name+'].['+b.name+']'', '''+replace(replace(b.name,'_',''),'.abc','')+''''
from
syso……