views:

147

answers:

4

This warning message I get from time to time from SQL server ...

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

Is this just saying that a value that was Null is being set to something other than Null. Why do I need to be 'warned' about this?

+3  A: 

No, it tells you that a NULL value is passed to an aggregate function. And since aggregate functions ignore NULL values (with the exception of COUNT), this could be unwanted behaviour. Therefore, you are warned.

Maximilian Mayerl
+1 for mentioning count which I forgot to.
Wade73
+2  A: 

You have ansi warnings turned on, and are using an aggregate (sum, max, min, ...) on a column which contains a null value.

SET ANSI_WARNINGS OFF

Quote:

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.

OMG Ponies
+1 For posting a solution to the unwanted behavior
Wade73
A: 

The most common instance of this is likely to be doing a SELECT COUNT(<column>) command. Any <column> entries that are null will be ignored.

ck
+3  A: 

You are getting this because nulls can't be evaluated. So unless you are using is null, a null is neither greater, less than, or equal to anything. Which means if you are using MAX() those rows with a null value will be ignored. Now you can wrap the column with an isnull function, and you will no longer get the message.

Wade73