Solved

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

Posted on 2011-03-08
5
569 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL: Transformation or Pivot 3 37
SQL Server Error: 4060 8 33
T-SQL Query 9 37
Generate list for insert to sql list 46 18
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

752 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