sql如何把查询到的NULL替换成空值?

如题所述

1、这要看你如何保存你查询的结果。只能是你把你查询的结果保存为0,查询不会改变原本存在的值。表名test,字段a=.null.(int型),字段b=1,字段c=2 :select * from test into tabel test1
update set a=0 where a=.null。

2、用 IsNull(字段名, '')  可以将NULL的字段转换为空值,这在多个字段连接时很有用,因为NULL值+任何字段都是NULL。

3、将NULL替换为空create procedure fill_null@tablename varchar(100) --表名asdeclare @colname varchar(100)declare col_cur cursor for select c.name from syscolumns c,sysobjects o where c.id=o.id and o.name=@tablename open col_curfetch next from col_cur into @colnamewhile @@fetch_status!=-1beginexec ('update '+@tablename+' set '+@colname+'='''' where '+@colname+' is null' )fetch next from col_cur into @colnam endclose col_curdeallocate col_cur

温馨提示:内容为网友见解,仅供参考
第1个回答  2018-01-05

isnull(expression,'') 就是将null换成 0长度字符啊

isnull(expression,0) 才是将null换成 0 呢

select isnull(expression,'') from tab;

你的数据类型是数值型,替换后将会将空字符值隐式转换为0。

无论什么值,用isnull函数转换后都要根据原有值类型匹配。

相似回答