SQL, Null value is eliminated by an aggregate or other SET operation.

Hi Experts,

The error message below showed up after I ran the query . I have checked the sub-query and there was no null value in there. I do not know if the warning message will affect the result or not?  Thank you.

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

(2 row(s) affected)

SELECT  companyname 
      , SUM(CASE WHEN LoanAmountFinanced <='2500.00' THEN 1 ELSE 0 END) AS NUMBEROFLOANSLESS2500
      , SUM(CASE WHEN LoanAmountFinanced <='6000.00' AND LoanAmountFinanced >'2500.00'THEN 1 ELSE 0 END) AS NUMBEROFLOANS2500TO6000
      , SUM(CASE WHEN LoanAmountFinanced <='10000.00' AND LoanAmountFinanced >'6000.00'THEN 1 ELSE 0 END) AS NUMBEROFLOANS6000TO10000
      , SUM(CASE WHEN LoanAmountFinanced <='20000.00' AND LoanAmountFinanced >'10000.00'THEN 1 ELSE 0 END) AS NUMBEROFLOANS10000TO20000
      , SUM(CASE WHEN LoanAmountFinanced >='20000.00' THEN 1 ELSE 0 END) AS NUMBEROFLOANSOVER20000
      , SUM(CASE WHEN LoanAmountFinanced <='2500.00' THEN LoanAmountFinanced ELSE 0 END) AS LOANSLESS2500
      , SUM(CASE WHEN LoanAmountFinanced <='6000.00' AND LoanAmountFinanced >'2500.00'THEN LoanAmountFinanced ELSE 0 END) AS LOANS2500TO6000
      , SUM(CASE WHEN LoanAmountFinanced <='10000.00' AND LoanAmountFinanced >'6000.00'THEN LoanAmountFinanced ELSE 0 END) AS LOANS6000TO10000
      , SUM(CASE WHEN LoanAmountFinanced <='20000.00' AND LoanAmountFinanced >'10000.00'THEN LoanAmountFinanced ELSE 0 END) AS LOANS10000TO20000
      , SUM(CASE WHEN LoanAmountFinanced >='20000.00' THEN LoanAmountFinanced ELSE 0 END) AS LOANSOVER20000
      , MAX(CASE WHEN LoanAmountFinanced <='2500.00' THEN TILAAPR END ) AS HIGHAPRFOR0TO2500
      , MIN(CASE WHEN LoanAmountFinanced <='2500.00' THEN TILAAPR END ) AS LOWAPRFOR0TO2500
      , MAX(CASE WHEN LoanAmountFinanced >'2500.00' THEN TILAAPR END ) AS HIGHAPRFOROVER2500
      , MIN(CASE WHEN LoanAmountFinanced >'2500.00' THEN TILAAPR END ) AS LOWAPRFOROVER2500
INTO #LOANSETA
FROM (
		SELECT S.companyname  
			  , L.LoanID 
			  , L.LoanAmountFinanced
			  , FN.TILAAPR
		FROM tblLoans L inner join 
			 #GROUPBYSTORES S ON S.STOREID= L.LoanStoreID
			 CROSS APPLY GetTILAInfo (LoanID) as FN
		WHERE L.LoanDate >= '20150101' and L.LoanDate < '20160101'   
		 
      ) A
GROUP BY  companyname

Open in new window

tanj1035Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris LuttrellSenior Database ArchitectCommented:
That is just a side effect of summing your data and you have nulls somewhere in your base data.
Here is a simple test to show where that particular message shows up only when you add a null value into your dataset.
CREATE TABLE #tmp (Name VARCHAR(20), NumValue NUMERIC);

SELECT SUM(T.NumValue)
FROM #tmp T;

INSERT INTO #tmp ( Name, NumValue )
VALUES	( 'Test', -- Name - varbinary(20)
		  100  -- NumValue - numeric
		  );

SELECT SUM(T.NumValue)
FROM #tmp T;

INSERT INTO #tmp ( Name, NumValue )
VALUES	( 'Test', -- Name - varbinary(20)
		  NULL  -- NumValue - numeric
		  );

SELECT SUM(T.NumValue)
FROM #tmp T;

DROP TABLE #tmp;

Open in new window

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)
Warning: Null value is eliminated by an aggregate or other SET operation.

(1 row(s) affected)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
That's only a warning.
I understand that can be annoying especially if it appears in your application.
You can turn it off by executing the following command before the query:
SET ANSI_WARNINGS OFF
Chris LuttrellSenior Database ArchitectCommented:
PLEASE READ EVERYTHING ABOUT ANSI WARNINGS BEFORE CHANGING THAT SETTING!!!!!!!!
It is there and set to ON by default for a very good reason.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Where is saying that ON is the default value? By the MSDN article I posted above:
" The default value in the model database for SET ANSI_WARNINGS is OFF. If not specified, the setting of ANSI_WARNINGS applies. If SET ANSI_WARNINGS is OFF, SQL Server uses the value of the is_ansi_warnings_on column in the sys.databases catalog view."

Anyway, the OP can always set it back to ON after the SELECT statement.
SET ANSI_WARNINGS OFF

SELECT ...
(...)

SET ANSI_WARNINGS ON
Chris LuttrellSenior Database ArchitectCommented:
True, Vitor.  And good example of how to do this for the one query and then turn it back on.  I just see too many people think, "Oh, I should just always turn that off so it will never get in my way."   But not think or realize the other effects of making that change.
tanj1035Author Commented:
Thank Vitor and Chris' sharing.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.