首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

去掉多个字段显示出来的NULL的方法,很头疼啊总是不好用。解决方案

2012-05-21 
去掉多个字段显示出来的NULL的方法,很头疼啊,总是不好用。。。唉, 惆怅啊,大神救命。。。[解决办法]SQL codeISNU

去掉多个字段显示出来的NULL的方法,很头疼啊,总是不好用。。。
唉, 惆怅啊,大神救命。。。

[解决办法]

SQL code
ISNULL(字段名,‘’)
[解决办法]
isnull(col,'') as col
就可以去掉null
[解决办法]
SQL code
select *  from (select IsNull(a.charge_id,0)as charge_id ,IsNull(a.charge_name,0)as charge_name,IsNull(d.division_name,0)as division_name,IsNull(e.dept_name,0)as dept_name,IsNull(f.section_name,0)as section_name,IsNull(b.post_name,0)as post_id,IsNull(a.post_id,0)as post_id,IsNull(c.division_id,0)as division_id,IsNull(c.dept_id,0)asdept_id,IsNull(c.section_id ,0)as  section_idfrom charge_mst a left join post_mst b on a.post_id = b.post_id inner join cddsc_trn c on c.charge_id = a.charge_id left join division_mst d on c.division_id = d.division_id  and c.division_id <> '0' left join dept_mst e on c.division_id = e.division_id  and c.dept_id = e.dept_id  and c.dept_id <> '0' left join section_mst f on c.division_id = f.division_id  and c.dept_id = f.dept_id  and c.section_id = f.section_id  and c.section_id <> '0') as g  where 1=1
[解决办法]
case when 也可以
[解决办法]
可以用isnull()函数,比如地址字段,是字符串类型,当地址没有记录时可以用isnull(地址字段名,'--'),当地址没有数据时,就用--代替,就不显示null了。当然--可以换成你想要的代替内容。如果是数据类型,如年龄字段,就不能加引号了,如年龄没有记录时,可以这样写isnull(年龄字段名,0),就会用0代替null了。

热点排行