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

 我来答
妞儿妈妈time
推荐于2019-11-10 · TA获得超过5119个赞
知道小有建树答主
回答量:44
采纳率:0%
帮助的人:5231
展开全部

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

风风风姬姬姬
2018-01-05 · TA获得超过8263个赞
知道小有建树答主
回答量:19
采纳率:100%
帮助的人:2868
展开全部

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

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

select isnull(expression,'') from tab;

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

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

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式