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

tanj1035
tanj1035 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Database Architect
Commented:
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

Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
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 Architect

Commented:
PLEASE READ EVERYTHING ABOUT ANSI WARNINGS BEFORE CHANGING THAT SETTING!!!!!!!!
It is there and set to ON by default for a very good reason.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
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 Architect

Commented:
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.

Author

Commented:
Thank Vitor and Chris' sharing.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial