Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Null value is eliminated by an aggregate or other SET operation. Expand / Collapse
Author
Message
Posted Friday, July 11, 2008 9:56 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 9, 2014 1:53 PM
Points: 320, Visits: 413
Hi all! Happy Friday!
ok, I came across a stored proc that is sending out this error when it runs:

"Null value is eliminated by an aggregate or other SET operation."

here is the existing code partial piece of code: MIN(u.ITEM) AS UnitItem

now the case here is that there is a NULL value in the column. What is the proper syntax for checking for nulls in this aggregate situation?? (I have tried a couple different ways and failed)

thank you in advance!



Thank you!!,

Angelindiego

Post #532612
Posted Friday, July 11, 2008 7:22 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:40 AM
Points: 35,265, Visits: 31,754
You don't have to...

SET ANSI_WARNINGS OFF

... will eliminate this expected error message.

Just to be sure about a couple of things, you might want to post the proc for a look-see...


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #532921
Posted Monday, July 14, 2008 1:05 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
or ...

just replace your code to

MIN(isnull(u.ITEM,0)) AS UnitItem




karthik
Post #533293
Posted Monday, July 14, 2008 8:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 9, 2014 1:53 PM
Points: 320, Visits: 413
thank you both!! I am off to fix the problem!! Have a great week!


Thank you!!,

Angelindiego

Post #533533
Posted Tuesday, July 15, 2008 2:35 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 9:05 PM
Points: 441, Visits: 933
This is not an error message. SS2K is simply telling you that it ignore NULL values when performing an aggregate operation on records.

Such as

5, NULL, 7

SUM will produce the result 12 WITH the warning message.

Anything added, subtracted, etc. to NULL yields in NULL. 5 + NULL + 7 --> NULL.
You could filter out the NULL values before calling the aggregate.


Regards
Post #534757
Posted Tuesday, July 15, 2008 3:00 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 9, 2014 1:53 PM
Points: 320, Visits: 413
thank you for the clarification, I appreciate it!


Thank you!!,

Angelindiego

Post #534772
Posted Thursday, July 26, 2012 1:42 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:49 AM
Points: 62, Visits: 326
But we want use in view .is that possible ??
Post #1335595
Posted Wednesday, August 15, 2012 10:21 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, September 18, 2014 11:10 PM
Points: 4,573, Visits: 8,351
dineshvishe (7/26/2012)
But we want use in view .is that possible ??

Yes, of course.
Just use SET ANSI_WARNINGS OFF in procedures which select from the view.
Post #1345650
Posted Tuesday, January 22, 2013 4:27 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:51 PM
Points: 62, Visits: 91
hi everyone.....i am the beginner of sql......can anyone help me to find out the mistake where i made????ive tried many times bt again nd again i gt same result"null value is eliminated by an aggregate or other set operation'.....my code completed successfully bt which doesnt show the result bcz of this warning message....can anyone help me??????



declare getcur cursor
for select sd.roll_no
from student_details sd
where sd.degree_id = @degree_id
AND sd.branch_id = @branch_id
AND sd.course_id = @course_id
AND sd.batch = @batch

open getcur
FETCH NEXT FROM getcur INTO @roll_no
WHILE @@FETCH_STATUS = 0
BEGIN

INSERT INTO #temp
SELECT sd.reg_no,
sd.student_name,
bd.branch_name,
cd.course_name,
r.noof_semester,
max(isnull(sm.sem_attended,0))as sem_attended,
@is_completed as is_completed,
rs.sub_code,
rs.sub_name,
case when sm.int_mark_obtained is null then 0 else @int_mark_obtained end,
case when sm.ext_mark_obtained is null then 0 else @ext_mark_obtained end,
isnull(sm.int_mark_obtained,0)+isnull(sm.ext_mark_obtained,0)as total_marks,
case when sm.exam_status='p' then 'PASS' when sm.exam_status= 'f' then 'fail' end exam_status


FROM student_details sd
INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no
INNER JOIN regulation_subject rs ON rs.regulation_sub_id = sm.regulation_sub_id
INNER JOIN regulation r ON r.regulation_no= rs.regulation_no
INNER JOIN course_details cd ON cd.course_id = sm.course_id
INNER JOIN branch_details bd ON bd.branch_id=sd.branch_id
WHERE @noof_semester =(select max(@sem_attended) from student_marks sm
where sm.roll_no=@roll_no)
AND sd.roll_no = sm.roll_no
and @batch=2007 and @course_id=99

group by
sd.reg_no,
sd.student_name,
bd.branch_name,
cd.course_name,
r.noof_semester,
rs.sub_code,
rs.sub_name,
sm.int_mark_obtained,
sm.ext_mark_obtained,
sm.exam_status

if @noof_semester=max(@sem_attended)
begin
set @is_completed='yes'
end
else
begin
set @is_completed='no'
end

fetch next from getcur into @roll_no
end


select *from #temp
order by reg_no

close getcur
deallocate getcur
drop table #temp
Post #1409925
Posted Tuesday, January 22, 2013 4:29 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:51 PM
Points: 62, Visits: 91
hi everyone.....i am the beginner of sql......can anyone help me to find out the mistake where i made????ive tried many times bt again nd again i gt same result"null value is eliminated by an aggregate or other set operation'.....my code completed successfully bt which doesnt show the result bcz of this warning message....can anyone help me??????



declare getcur cursor
for select sd.roll_no
from student_details sd
where sd.degree_id = @degree_id
AND sd.branch_id = @branch_id

open getcur
FETCH NEXT FROM getcur INTO @roll_no
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #temp
SELECT sd.reg_no,
sd.student_name,
bd.branch_name,
cd.course_name,
r.noof_semester,
max(isnull(sm.sem_attended,0))as sem_attended,
@is_completed as is_completed,
rs.sub_code,
rs.sub_name,
case when sm.int_mark_obtained is null then 0 else @int_mark_obtained end,
case when sm.ext_mark_obtained is null then 0 else @ext_mark_obtained end,
isnull(sm.int_mark_obtained,0)+isnull(sm.ext_mark_obtained,0)as total_marks,
case when sm.exam_status='p' then 'PASS' when sm.exam_status= 'f' then 'fail' end exam_status


FROM student_details sd
INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no
INNER JOIN regulation_subject rs ON rs.regulation_sub_id = sm.regulation_sub_id
INNER JOIN regulation r ON r.regulation_no= rs.regulation_no
INNER JOIN course_details cd ON cd.course_id = sm.course_id
INNER JOIN branch_details bd ON bd.branch_id=sd.branch_id
WHERE @noof_semester =(select max(@sem_attended) from student_marks sm
where sm.roll_no=@roll_no)
AND sd.roll_no = sm.roll_no
and @batch=2007 and @course_id=99

group by
sd.reg_no,
sd.student_name,
bd.branch_name,
cd.course_name,
r.noof_semester,
rs.sub_code,
rs.sub_name,
sm.int_mark_obtained,
sm.ext_mark_obtained,
sm.exam_status

if @noof_semester=max(@sem_attended)
begin
set @is_completed='yes'
end
else
begin
set @is_completed='no'
end

fetch next from getcur into @roll_no
end


select *from #temp
order by reg_no

close getcur
deallocate getcur
drop table #temp
Post #1409929
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse