Avatar of tanj1035
tanj1035

asked on 

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

Microsoft SQL Server

Avatar of undefined
Last Comment
tanj1035
ASKER CERTIFIED SOLUTION
Avatar of Chris Luttrell
Chris Luttrell
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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
PLEASE READ EVERYTHING ABOUT ANSI WARNINGS BEFORE CHANGING THAT SETTING!!!!!!!!
It is there and set to ON by default for a very good reason.
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
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.
Avatar of tanj1035
tanj1035

ASKER

Thank Vitor and Chris' sharing.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo