Solved

Null value is eliminated by an aggregate or other SET operation

Posted on 2010-08-16
9
437 Views
Last Modified: 2012-05-10
INSERT INTO dbo.[BILLING.DEFAULT] (ACCOUNT_ID, ACCOUNT_NAME, TOTAL_MINUTES, TOTAL_PRICE)
Hi All,
with support of "Experts Exchanhe" Members i have the following "WORKIING" query

SELECT
[dbo].[BILLING.PLAN].ACCOUNT_ID,
[dbo].[BILLING.PLAN].ACCOUNT_NAME,
SUM([dbo].[BILLING.PLAN].CALL_DURATION) / 60 AS TOTAL_MINUTES,
CAST(SUM([dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL) AS DECIMAL(27, 2)) AS TOTAL_PRICE
FROM [dbo].[BILLING.PLAN]
GROUP BY [dbo].[BILLING.PLAN].ACCOUNT_ID, [dbo].[BILLING.PLAN].ACCOUNT_NAME

My problem is comming from calcualtions. I hava a positive data into CALL.DURATION and TOTAL_PRICE_PER_CALL.

Please help me to avoud the resutls like:

Warning: Null value is eliminated by an aggregate or other SET operation.
(1 row(s) affected)

ACCOUNT_ID      ACCOUNT_NAME      TOTAL_MINUTES      TOTAL_PRICE
NULL      BOB      -21201271      -21237349.27
0
Comment
Question by:batman_k
  • 3
  • 3
  • 3
9 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 400 total points
Comment Utility
The warning is coming from NULL values in either or both of the SUMmed columns CALL.DURATION and TOTAL_PRICE_PER_CALL. Either that is correct or a warning of inappropriate data.

Please try the following for test:

SELECT
[dbo].[BILLING.PLAN].ACCOUNT_ID,
[dbo].[BILLING.PLAN].ACCOUNT_NAME,
SUM([dbo].[BILLING.PLAN].CALL_DURATION) / 60 AS TOTAL_MINUTES,
CAST(SUM([dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL) AS DECIMAL(27, 2)) AS TOTAL_PRICE,
count(*) as Records,
min([dbo].[BILLING.PLAN].CALL_DURATION) as Min_Duration,
max([dbo].[BILLING.PLAN].CALL_DURATION) as Max_Duration
FROM [dbo].[BILLING.PLAN]
GROUP BY [dbo].[BILLING.PLAN].ACCOUNT_ID, [dbo].[BILLING.PLAN].ACCOUNT_NAME

and post the result for above record.
0
 
LVL 2

Author Comment

by:batman_k
Comment Utility
Hi Qlemo,
do i need to create columns
Reccords, Min Duration and  Max Duration?
somwhere between records, min and max is the error

Msg 121, Level 15, State 1, Line 2
The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
That is thought to be used without the INSERT, only the SELECT (as shown). We don't want the values to be inserted yet.
0
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 100 total points
Comment Utility
Problem is one of the value coming as NULL, so you getting that warning message.
- this is just warning message,it wont stop your execution.

to debug that Firstly fire below query

SELECT
[dbo].[BILLING.PLAN].ACCOUNT_ID,
[dbo].[BILLING.PLAN].ACCOUNT_NAME,
SUM([dbo].[BILLING.PLAN].CALL_DURATION)  / 60 AS TOTAL_MINUTES,
CAST(SUM([dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL) AS DECIMAL(27, 2)) AS TOTAL_PRICE
FROM [dbo].[BILLING.PLAN]
WHERE [dbo].[BILLING.PLAN].CALL_DURATION IS NULL OR [dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL IS NULL
GROUP BY [dbo].[BILLING.PLAN].ACCOUNT_ID, [dbo].[BILLING.PLAN].ACCOUNT_NAME


so you will get the data with NULL values.



still if u want to run query and want to that warning message
use ISNULL

SELECT
[dbo].[BILLING.PLAN].ACCOUNT_ID,
[dbo].[BILLING.PLAN].ACCOUNT_NAME,
SUM(IsNull([dbo].[BILLING.PLAN].CALL_DURATION,0))  / 60  AS TOTAL_MINUTES,
CAST(SUM(IsNull([dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL,0)) AS DECIMAL(27, 2)) AS TOTAL_PRICE
FROM [dbo].[BILLING.PLAN]
WHERE [dbo].[BILLING.PLAN].CALL_DURATION IS NULL OR [dbo].[BILLING.PLAN].TOTAL_PRICE_PER_CALL IS NULL
GROUP BY [dbo].[BILLING.PLAN].ACCOUNT_ID, [dbo].[BILLING.PLAN].ACCOUNT_NAME

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 19

Expert Comment

by:Bhavesh Shah
Comment Utility

Please make a note,forget to put avoid word above

still if u want to run query and want to "avoid" that warning message
use ISNULL



0
 
LVL 2

Author Comment

by:batman_k
Comment Utility
Hi All,

Qlemo
................
ACCOUNT_ID      ACCOUNT_NAME      TOTAL_MINUTES      TOTAL_PRICE      Records      Min_Duration      Max_Duration
11793417      bob      -21201271.400000      -21237349.27      45283      -1277307175      29787

Brichsoft
..................
ACCOUNT_ID      ACCOUNT_NAME      TOTAL_MINUTES      TOTAL_PRICE
11793417      bob      8.866666      NULL

0
 
LVL 19

Expert Comment

by:Bhavesh Shah
Comment Utility
PROBLEM IS "TOTAL_MINUTES" Contain NULL Value.

thats why problem is coming.
so either you correct your data, or u can use IsNull() before doing SUM()

SUM(IsNull([dbo].[BILLING.PLAN].CALL_DURATION,0))
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
You have a very big negative value for Call_Duration - that one shown above (-1277307175). You should investigate why that value is there.
0
 
LVL 2

Author Closing Comment

by:batman_k
Comment Utility
I found where the dormant record was residing.
Thanks for your support! Both ideas made my query far more precise.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now