在使用sql数据库的过程,由于服务器设置不当导致sql server的某个字段为空,导致部分内容显示失败,就需要将为空的字符替换为制定的字符。

例子,sql语句:

use 数据库

update news set author='jb51' where author is null

强烈建议操作以前先备份下数据库。

说明:使用指定的替换值替换 NULL。

语法:ISNULL ( check_expression , replacement_value )

参数:

check_expression:将被检查是否为 NULL 的表达式。check_expression 可以为任何类型。

replacement_value:当 check_expression 为 NULL 时要返回的表达式。replacement_value 必须是可以隐式转换为 check_expresssion 类型的类型。

返回值:返回与 check_expression 相同的类型。(链接:sql语句大全)

注释:如果 check_expression 不为 NULL,则返回它的值;

否则,在将 replacement_value 隐式转换为 check_expression 的类型(如果这两个类型不同)后,则返回前者。

实例:

select avg(isnull(weight, 50))

from production.product;

请勿使用 ISNULL 查找 NULL 值。

而应使用 IS NULL。

例子,sql语句查找 weight 列中存在 NULL 的所有产品。

请注意 IS 和 NULL 之间的空格。

use adventureworks2008r2;

go

select name, weight

from production.product

where weight is null;

go

sql数据中如何判断变量或字段是否为null

判断变量是否为NULL:

IF (@VaribleName IS NULL)

选择字段值为NULL的记录:

WHERE COLUMN_NAME IS NULL

ISNULL()函数:

isnull(@variblename, 'defaultvalue')

isnull(column_name, 'default value')

sql数据库中isnull应用举例/sql查询空记录is null

有时需要在sql server中查找空的记录可以用sql语句来实现

比如需要查找日期字段为 null 的数据可以以下sql语句:

select * from db whete date is null

如果要查找不为空的可以用

select * from db whete not date is null

isnull在sql server 中的用法

isnull

使用指定的替换值替换 NULL。

语法

ISNULL ( check_expression , replacement_value )

参数

check_expression

将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。

replacement_value

在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。

返回类型

返回与 check_expression 相同的类型。

注释

如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。

a,将 isnull 与 avg 一起使用

查找所有书的平均价格,用值 $10.00 替换 titles 表的 price 列中的所有 NULL 条目。

use pubs

go

select avg(isnull(price, $10.00))

from titles

go

结果集:

--------------------------

14.24

(1 row(s) affected)

您可能感兴趣的文章:

sql中isnull用法实例详解

sql语句中isnull函数用法 实例教程

sql数据库中null值与IsNull函数用法详解

sql server中ISNULL函数与Mysql中IFNULL函数的用法

有关sql server中isnull的问题

更多推荐

oracle判断是否为空为空赋值,sql数据库中ISNULL函数用法 sql语句判断值是否为空...