alter function GetDtoScheme( @dtoOldName varchar(50), @dtoNewName varchar(50), @dbName varchar(50)) returns @scheme table ( columnName nvarchar(128), newColumnName nvarchar(128) ) as begin insert into @scheme select syscolumns.name,replace(syscolumns.name,@dtoOldName,@dtoNewName) FROM syscolumns WHERE syscolumns.id = object_id(@dbName+'.dbo.AA_'+@dtoOldName+'_Ext') and syscolumns.name like '%'+@dtoOldName+'%' return end