日期:2014-05-20  浏览次数:20472 次

有没有朋友可以实现在查询语句中实现当查出的某个字段数据是null时自动转化为0
有没有朋友可以实现在查询语句中实现当查出的某个字段数据是null时自动转化为0   ,   我需要把查询出的数据填到另一个表中,不希望插入NULL值,希望能自动转化为0然后再插入。谢谢

------解决方案--------------------
select isnull(testcolumn,0) as testcolumn from testtable
------解决方案--------------------
isnull(字段,0) as 字段名
------解决方案--------------------
楼主,这个问题不是C#的问题...

要根据不同的数据库提供的函数是不一样的..

楼主查一下自己使用的数据库...

这种函数数据库必然要提供的..
------解决方案--------------------
isnull(字段,0) as 字段
------解决方案--------------------
select (case column when null then 0 else column) as testcolumn from testtable
------解决方案--------------------
两种方法
isnull(字段,0) as 字段
case 字段 when null then 0 else 字段
------解决方案--------------------
select isnull(testcolumn,0) as testcolumn from testtable

------解决方案--------------------
select (case column when null then 0 else column) as testcolumn from testtable
------解决方案--------------------
数据库不同,用的函数不同
Sql Server :select name,isnull(age,0) age from t_user;
Oracle :select name,nvl(age,0) age from t_user;
其他的数据库就不知道了
目前就熟悉这两种数据库