本段代码的作用是执行循环替换操作,在做这个功能时,转义字符耽误了不少时间,参数是中文时,拼接SQL 语句需要用四个单引号来完成一个单引号所代表的作用。
?
declare c1 cursor for
?select t_code from dsn_table where (t_code like 'zgjwj_jxx%')
open c1
declare?? @tableName nvarchar(400)
declare @sql?? nvarchar(400)
declare @newjh varchar(400)
declare @oldjh varchar(400)
set @newjh='高223-斜245'
set @oldjh='高223-斜25'
fetch next from c1 into @tableName
WHILE(@@FETCH_STATUS = 0)
begin
SET @sql=N' update ' [email protected] + ' set jh= [email protected]+'''' +' where [email protected]+'''';
--SEt @sql=N'select top 1 jh from [email protected]
exec sp_executesql @sql;
--select? top 1 @tableName from jdsn_jkzz
fetch next from c1 into @tableName
end
CLOSE c1
DEALLOCATE c1