Also, if you don't want ot include columns with NULL values in the calculation, you will have to filter those in the WHERE clause:
WHERE YourField is not NULL
Main Topics
Browse All TopicsA stored procedure I am running is throwing the warning "Warning: Null value is eliminated by an aggregate or other SET operation."
I would like to trap and suppress this warning within the stored procedure. How do I do that?
I cannot SET ANSI_WARNINGS OFF because I need it on to use indexed views (I think).
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
SET ANSI_WARNINGS OFF
will do it
SET ANSI_WARNINGS ON
will switch it back for
rest of code
see
example below:
DROP TABLE tabcount
--GO
SET NOCOUNT ON
GO
CREATE TABLE tabcount (
pkey int IDENTITY NOT NULL CONSTRAINT pk_tabcount PRIMARY KEY,
col1 int NULL)
GO
INSERT tabcount (col1) VALUES (10)
GO
INSERT tabcount (col1) VALUES (15)
GO
INSERT tabcount (col1) VALUES (20)
GO
INSERT tabcount (col1) VALUES (NULL)
GO
SET ANSI_WARNINGS OFF
SELECT AVG(col1) A1,
AVG(ISNULL(col1,0)) A2,
COUNT(col1) C1,
COUNT(ISNULL(col1,0)) C2,
COUNT(*) C3
FROM tabcount
SET ANSI_WARNINGS ON
GO
Business Accounts
Answer for Membership
by: SireesPosted on 2006-09-13 at 13:30:16ID: 17515409
I got this from some other EE member:
It means that a field you are performing an aggregate calculation on (e.g. AVG(YourField)) contains NULL values. A NULL cannot be interpreted in operations like this and so any NULL values are ignored.
supposing you have 3 records with the following values
2.00
NULL
2.00
If you were to do an AVG on this column, you'd get the Warning message you have, and the result would be 2.00 (doesn't count the NULL row when working out the average).
However, if you use "AVG(ISNULL(YourField, 0))" then you'd get the correct result of 1.33
So, what you should do if put the ISNULL() around your column