Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Null value is eliminated?

Author  Topic 

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-05-11 : 17:54:33
I'm trying to understand someone else's code, and it's getting this error:

Msg 8153, Level 0, State 1
Warning: Null value is eliminated by an aggregate or other SET operation.

What does that mean? I tried doing a search but no one seems explain it in plain English.

Here's the query, in case it helps:

SELECT
a.c_id
, a.u_id
, a.visit_date
, [last_trans] = MAX(t.trans_date)
FROM #AddLastTrans a
LEFT JOIN Trans t
ON a.c_id = t.c_id
AND a.u_id = t.u_id
AND a.visit_date >= t.trans_date
GROUP BY
a.c_id
, a.u_id
, a.visit_date


I think they're trying to get the most recent transaction for each visit, but it seems like whoever wrote the script (they're not here anymore) ignored or didn't notice the warning message and just kept going. Oh, and all of the fields involved are NOT NULL.

Any idea what the error is? Thanks!

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-11 : 18:12:16
It is a message that means just what it says - that some null values were eliminated when doing the aggregate function. For example if you run this code, you will get the same message:
create table #tmp(id int);
insert into #tmp values (1);
insert into #tmp values (null);
insert into #tmp values (2);
select max(id) from #tmp;
drop table #tmp

Go to Top of Page

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-05-11 : 18:38:55
Oh, okay - so maybe those NULLs are created from the JOIN, since none of those fields can have NULL values. Thanks!


quote:
Originally posted by sunitabeck

It is a message that means just what it says - that some null values were eliminated when doing the aggregate function. For example if you run this code, you will get the same message:
create table #tmp(id int);
insert into #tmp values (1);
insert into #tmp values (null);
insert into #tmp values (2);
select max(id) from #tmp;
drop table #tmp



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-11 : 18:59:05
Yes the NULLs are due to the LEFT JOIN, which is an outer join. For the rows that don't match the criteria in the join, you'll get NULLs in the columns of the "RIGHT" table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -