declare @curTable nvarchar(500), @FilterStr nvarchar(500);--过滤字符串 字符串及之后的数据将被替换为空 set @FilterStr=‘<‘; set @curTable=‘B07‘; DECLARE @SQLList nvarchar(4000), @tableName VARCHAR(10), @name VARCHAR(10), @type VARCHAR(10); set @SQLList=‘‘; BEGIN -- 定义游标. DECLARE c_test_main CURSOR FAST_FORWARD FOR -- select [dbid],[name] from sysdatabases where dbid>4;--查询数据库名称 select b.name as tableName,a.name as columnName,c.name as columnType from syscolumns a inner join sysobjects b on a.id=b.id inner join systypes c on a.xtype=c.xtype WHERE a.id=OBJECT_ID(N‘[‘+@curTable+‘]‘) And c.name not like ‘sysname‘ ORDER BY colid -- 打开游标. OPEN c_test_main; WHILE 1=1 BEGIN -- 填充数据. FETCH NEXT FROM c_test_main INTO @tableName,@name,@type; -- 假如未检索到数据,退出循环. IF @@fetch_status!= 0 BREAK; if @type=‘varchar‘ begin --select @tableName,@name,@type; set @SQLList=@SQLList+‘;update [‘+@tableName+‘] set [‘+@name+‘]=replace([‘+@name+‘],substring([‘+@name+‘],charindex(‘‘‘+@FilterStr+‘‘‘,[‘+@name+‘]),len([‘+@name+‘])),‘‘‘‘); ‘ end END; -- 关闭游标 CLOSE c_test_main; -- 释放游标. DEALLOCATE c_test_main; END select @SQLList;
原文地址:http://www.cnblogs.com/xyzhuzhou/p/3858308.html