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

SQL Server中,用isnull(expression,'')时,如果存在NULL,则会替换成0,请问如何把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-02-26
isnull(expression,'') 就是将null换成 0长度字符啊
isnull(expression,0) 才是将null换成 0 呢

select isnull(expression,'') from tab;本回答被提问者和网友采纳
第2个回答  2013-07-10
你的数据类型是数值型,替换后将会将空字符值隐式转换为0
无论什么值,用isnull函数转换后都要根据原有值类型匹配
相似回答