Solved

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

Posted on 2011-03-08
5
564 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
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

830 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