<pre class="c" name="code">
declare @Str1 varchar(200) ,@Str2 varchar(200) , @ni int
set @ni=1
set @Str1='',@Str2=''
while @ni<=57
begin
set @Str1=@Str1+',C'+ltrim(rtrim(cast(@ni as char(2))))
set @Str2=@Str2+',C'+ltrim(rtrim(cast(@ni as char(2))))+'=你的值'
set @ni=@ni+1
end
set @Str1=substring(@Str1,2,200)
set @Str2=substring(@Str2,2,200)
exec('select '+@Str1+' from Table')--查詢
exec('update Table set '+@Str2) --更新
--MS-SQL
--以DB=pubs的TABLE=jobs為例,修改下列註解行語法.
use pubs
declare @name sysname
declare cl cursor for select name from syscolumns where id = (select id from sysobjects where name = 'jobs')
open cl
fetch next from cl into @name
while @@fetch_status = 0
begin
select 'update jobs set ' + @name + ' = [my_value] WHERE [my_condition]'
--exec('update jobs set ' + @name + ' = [my_value] WHERE [my_condition]')
fetch next from cl into @name
end
close cl
deallocate cl
--希望有幫助^^