<pre><pre class="text">
使用方法:exec updatecol table1,2,3,'NewValue'
参数:表名,起始列,终止列,新值(如不为字符类型需进行转换)
建立存贮过程:
CREATE PROCEDURE UpdateCol @YourTable Char(50),@StartCol int,@EndCol
int,@ReplaceValue char(20)
as
declare @FieldName char(50)
DECLARE UpdateWhere CURSOR FOR select name from syscolumns where (id=
(select id from sysobjects where name=@YourTable))and(colid&gt;=@StartCol)
and(colid&lt;=@EndCol)
OPEN UpdateWhere
FETCH NEXT FROM UpdateWhere INTO @FieldName
WHILE @@FETCH_STATUS = 0 BEGIN
exec('Update '+@YourTable+' Set '+@FieldName+'=&quot;'+@ReplaceValue+'&quot;')
FETCH NEXT FROM UpdateWhere INTO @FieldName
END
CLOSE UpdateWhere
DEALLOCATE UpdateWhere
</font></pre>