The warning is due to line for when the SEQUENCE_NUMBER is compared to "IS NULL".

When I run the SQL below, I get this warning message :
Warning: Null value is eliminated by an aggregate or other set operation

The warning is due to line for when the SEQUENCE_NUMBER is compared to "IS NULL".

Why is this? Can someone tell me how I can fix this?


1   DECLARE @MAXIMUM INT
2   DECLARE @MINIMUM INT

3   SELECT @MAXIMUM =
4   ISNULL(MAX(MyList.SEQUENCE_NUMBER),0) from
5   (select distinct (A_NUM),SEQUENCE_NUMBER from SHAKER WHERE SEQUENCE_NUMBER IS NULL) MyList
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Missus Miss_SellaneusCommented:
Its an informational message telling you that MAX(MyList.SEQUENCE_NUMBER),0) could never be null because a null value would never be accepted as a max value.
Missus Miss_SellaneusCommented:
Also, ISNULL returns a T/F.

I think you might want MAX(IIF(ISNULL(MyList.sequence_number),0,MyList.sequence_number))

Like this:

SELECT @MAXIMUM =
MAX(IIF(ISNULL(MyList.SEQUENCE_NUMBER),0,MyList.SEQUENCE_NUMBER))  from
(select distinct (A_NUM),SEQUENCE_NUMBER from SHAKER WHERE SEQUENCE_NUMBER IS NULL) MyList

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
Scott PletcherSenior DBACommented:
The code as written doesn't really make logical sense.

SEQUENCE_NUMBER in the inner query can only ever be NULL, since it has to match the condition "SEQUENCE_NUMBER IS NULL".  Thus, no matter what row(s) are in the table, or no rows at all, the result will always be NULL.

Maybe you really want to do this?:

SELECT
    @MAXIMUM = MAX(A_NUM),
    @MINIMUM = MIN(A_NUM)
FROM SHAKER
WHERE SEQUENCE_NUMBER IS NULL
brgdotnetcontractorAuthor Commented:
Thank you
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.