Solved

Null value is eliminated by an aggregate or other SET operation

Posted on 2010-08-16
9
438 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 69

Accepted Solution

by:
Qlemo earned 400 total points
ID: 33446244
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
ID: 33446409
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 69

Expert Comment

by:Qlemo
ID: 33446420
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 100 total points
ID: 33446541
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
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 33446549

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
ID: 33446722
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
ID: 33446981
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 69

Expert Comment

by:Qlemo
ID: 33447160
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
ID: 33447800
I found where the dormant record was residing.
Thanks for your support! Both ideas made my query far more precise.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

776 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