Wintle·旧居

个人blog移至:http://www.wintle.cn,欢迎光临。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

替换表中所有null为"无"的sql

Posted on 2005-08-20 16:59  Wintle  阅读(1175)  评论(0编辑  收藏  举报
先放一放。呵呵。

declare @newstr varchar(100)
set @newstr=''  --新字符

declare @table varchar(256)
set @table='year2004'  --

declare @upcol varchar(8000)
declare tb cursor local for
select upcol='update ['+b.name+'] set ['+a.name+']='''+@newstr+''' where ['+a.name+'] is null'
from syscolumns a join sysobjects b on a.id=b.id
where b.xtype='U' and a.status>=0
 
and a.xusertype in(175,239,231,167and b.name=@table
open tb
fetch next from tb into @upcol
while @@fetch_status=0
begin
 
exec(@upcol)
 
fetch next from tb into @upcol
end
close tb
deallocate tb