Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server Update Statement error:   Warning: Null value is eliminated by an aggregate or other SET operation.

Posted on 2011-03-08
5
Medium Priority
?
580 Views
Last Modified: 2012-05-11
When I run this I get the error: Warning: Null value is eliminated by an aggregate or other SET operation.

I thought the isnull function would remove the error but it's not.  The query is actually running but I don't want the warning.  How can I handle this?

update hb
set PROGRAM_END_DATE = isnull(
(SELECT max(ef.END_DT) FROM AP_FACT..EN_FACT ef
where hb.program_assignment_id = ef.src_program_assignment_id
and ef.dim_program_id = 194 and
ef.END_DT < '2099-12-31 00:00:00.000'),'2099-12-31 00:00:00.000')
FROM #hbinterval hb

Thanks as always for your help,
Julia
0
Comment
Question by:rsmuckles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 35074497
this message is not an error .. its a warning about the eliminated records while aplying aggregation faunction...
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 35074558
agree its only a warning...

would this suffice?

(or add a where clause into the sub-query and ignore null date values...)
update hb
set PROGRAM_END_DATE = 
(SELECT max(coalesce(ef.END_DT,'2099-12-31 00:00:00.000'))
   FROM AP_FACT..EN_FACT ef
where hb.program_assignment_id = ef.src_program_assignment_id 
and ef.dim_program_id = 194 
and ef.END_DT < '2099-12-31 00:00:00.000')
FROM #hbinterval hb

Open in new window

0
 
LVL 26

Expert Comment

by:tigin44
ID: 35074565
this should work withoot warning


update hb
set PROGRAM_END_DATE = isnull(
(SELECT max(ISNULL(ef.END_DT, '01.01.1900')) FROM AP_FACT..EN_FACT ef
where hb.program_assignment_id = ef.src_program_assignment_id
and ef.dim_program_id = 194 and
ef.END_DT < '2099-12-31 00:00:00.000'),'2099-12-31 00:00:00.000')
FROM #hbinterval hb
0
 

Author Comment

by:rsmuckles
ID: 35074567
I get that.  I should have used the word warning instead of error but is there a way to have this warning not appear?

It's a warning that there are some null ef.end_dt values and that those can't be 'maxed' right?  I thought I'd be handling the warning by using the isnull function which creates a dummy date in the case where there are null values.  Is there a way that I can run this that the warning won't happen?

update hb
set PROGRAM_END_DATE = isnull(
(SELECT max(ef.END_DT) FROM AP_FACT..EN_FACT ef
where hb.program_assignment_id = ef.src_program_assignment_id
and ef.dim_program_id = 194 and
ef.END_DT < '2099-12-31 00:00:00.000'),'2099-12-31 00:00:00.000')
FROM #hbinterval hb

0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 2000 total points
ID: 35074650
update hb
set PROGRAM_END_DATE = isnull(
(SELECT max(ef.END_DT) FROM AP_FACT..EN_FACT ef
where hb.program_assignment_id = ef.src_program_assignment_id
and ef.dim_program_id = 194 and
ef.END_DT < '2099-12-31 00:00:00.000')
,'2099-12-31 00:00:00.000')
FROM #hbinterval hb


the highlight component is/are what generates the Warning you need to address that part of the command
your isnull is doing some after event processing

see my previous comments
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question