Warning: Null value is eliminated by an aggregate or other SET operation.

简介:

Null 值会被聚合函数忽略,默认情况下,Sql Server会给出Warning:

Warning: Null value is eliminated by an aggregate or other SET operation.

这个Warning说明Null value 被聚合函数忽略,此时的 SET ANSI_WARNINGS 选项是ON状态,例如,count()函数不会计算null值,min/max函数不会计算null值。如果设置 SET ANSI_WARNINGS OFF ,SQL Server不会抛出 warning 消息。

1,忽略NULL 值

例如,结果是1,正确,但是出现一个Warning。

复制代码
use tempdb
go 

set ANSI_WARNINGS on 

if object_id('#dt_test','U') is not null
    drop table #dt_test

create table #dt_test
(    
    id int
)

insert into #dt_test
values(1),(null)

select min(id)
from #dt_test
复制代码

强烈推荐:将ANSI_Warnings选项设置为ON

2,查看当前DB的 ANSI_Warnings 选项的设置

select name,
    database_id,
    is_ansi_warnings_on
from sys.databases
where database_id=db_id()

 

引用《SET ANSI_WARNINGS》:

As the Warning says, NULLs are being ignored because we are using aggregate function (SUM, AVG). To avoid the warning we can use “set ansi_warnings off” before the script. Here is the modified script.

SET ANSI_WARNINGS OFF

When set to ON, if null values appear in aggregate functions, such as SUM, AVG, MAX, MIN, STDEV, STDEVP, VAR, VARP, or COUNT, a warning message is generated. When set to OFF, no warning is issued. 

SET ANSI_WARNINGS must be ON when you are creating or manipulating indexes on computed columns or indexed views. If SET ANSI_WARNINGS is OFF, CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail

 

参照文档:

SET ANSI_WARNINGS (Transact-SQL)

作者悦光阴
本文版权归作者和博客园所有,欢迎转载,但未经作者同意,必须保留此段声明,且在文章页面醒目位置显示原文连接,否则保留追究法律责任的权利。
分类: TroubleShooting




本文转自悦光阴博客园博客,原文链接:http://www.cnblogs.com/ljhdo/p/4873800.html,如需转载请自行联系原作者
目录
打赏
0
0
0
0
20
分享
相关文章
HashMap和Hashtable的key和value可以为null吗,ConcurrentHashMap呢
HashMap的key可以为null,value也可以为null;Hashtable的key不允许为null,value也不能为null;ConcurrentHashMap的key不允许为null
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
在Java中,使用mybatis-plus更新实体类对象到mysql,其中一个字段对应数据库中json数据类型,更新时报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
427 4
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
Using ‘value‘ pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value s
本文讨论了OpenCV中使用`createTrackbar`时遇到的"Using ‘value’ pointer is unsafe and deprecated"警告,并提供了通过设置空指针或使用回调函数来解决这个问题的方法。
Using ‘value‘ pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value s
|
7月前
解决微软云Azure Function运行报错-Value cannot be null. (Parameter ‘provider‘)
解决微软云Azure Function运行报错-Value cannot be null. (Parameter ‘provider‘)
144 4
|
7月前
|
【Azure 应用服务】Azure Function Python函数部署到Azure后遇见 Value cannot be null. (Parameter 'receiverConnectionString') 错误
【Azure 应用服务】Azure Function Python函数部署到Azure后遇见 Value cannot be null. (Parameter 'receiverConnectionString') 错误
【Azure Function】调试 VS Code Javascript Function本地不能运行,报错 Value cannot be null. (Parameter 'provider')问题
【Azure Function】调试 VS Code Javascript Function本地不能运行,报错 Value cannot be null. (Parameter 'provider')问题
【Azure 环境】Azure应用程序网关设置set_Cookie=key=value; SameSite=Strict; HTTPOnly,AzureAD登录使用cookie时使用不了的案例记录
【Azure 环境】Azure应用程序网关设置set_Cookie=key=value; SameSite=Strict; HTTPOnly,AzureAD登录使用cookie时使用不了的案例记录
【Python】已解决:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFram
【Python】已解决:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFram
1084 1
content‘ is declared but its value is never read.富文本编辑器中这里必须的script中添加setup,引入到set当中时,带title的富文本写法
content‘ is declared but its value is never read.富文本编辑器中这里必须的script中添加setup,引入到set当中时,带title的富文本写法
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等