日期:2014-05-17  浏览次数:21218 次

如何将全表中的 null值或空值,全部替换成 ‘NN’
全表300多列,800多行。
其中40%为空值或null。

请教如何用语句把所有空值或null全部替换成NN.

谢谢

------解决方案--------------------
确定把全部空值或NULL都替换成NN

SQL code
update tb set col='NN' where col='' or col is NULL

------解决方案--------------------
SQL code
declare @colname  varchar(100),
        @sql      varchar(3000)
set @sql=''
select  @colname=name from syscolumns where id=object_id('tb') 
set @sql='update tb set'+''+@colname+''+'=NN'+'where col='' or col is NULL'

exec (@sql)

------解决方案--------------------
SQL code
declare @colname  varchar(100),
        @sql      varchar(8000)
set @sql=''
declare cur_tbcolumn cursor
for
select  name from syscolumns where id=object_id('tb') 
fetch next from cur_tbcolumn
while @@fetch_status=0
begin
set @sql='update tb set '+@colname+'=''NN'''+'where '+@colname+'='''' or '+@colname+' is NULL'
exec (@sql)
set @sql=''
fetch next from cur_tbcolumn
end

------解决方案--------------------
SQL code
declare @colname  varchar(100),
        @sql      varchar(8000)
set @sql=''
declare cur_tbcolumn cursor
for
select  name from syscolumns where id=object_id('tb') 
OPEN cur_tbcolumn
fetch next from cur_tbcolumn
while @@fetch_status=0
begin
set @sql='update tb set '+@colname+'=''NN'''+'where '+@colname+'='''' or '+@colname+' is NULL'
exec (@sql)
set @sql=''
fetch next from cur_tbcolumn
end