Solved

What's wrong with the below query?

Posted on 2010-08-23
5
247 Views
Last Modified: 2012-06-27

Select DueDate, DeliveryDate,OrderNum
From Invnum Where OrderNum  in (select OrderNum from Items) and DocState in (1,3)
and OrderNum in
(
SELECT     isnull(SOno,'') FROM vuForInvNumTrig WHERE    (isnull(NoOfCntAllc,0) >                 isnull(Recd,0)) AND (POno = 'PO7943')
)

I am using the above query in a trigger its giving me an error like
'Null value is eliminated by an aggregate or other SET operation.'

When i execute the same query in a stored procedure window, it is returning results but with warning,

Warning: Null value is eliminated by an aggregate or other SET operation.
DueDate                 DeliveryDate            OrderNum            
----------------------- ----------------------- --------------------
8/30/2010               7/31/2010               SO4876              
No rows affected.
(1 row(s) returned)

Why this happens, please suggest a solution
0
Comment
Question by:mahmood66
5 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 33499081
this is not your full query.

problem is u doing some aggregate function and null value coming in that column because of warning msg is coming.

can u post ur trigger query?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33499090
I agree.

to start with, make sure your IN ( subquery) does not return NULLS:
and OrderNum in

(

SELECT     SOno FROM vuForInvNumTrig WHERE    (isnull(NoOfCntAllc,0) >                 isnull(Recd,0)) AND (POno = 'PO7943')

AND SOno IS NOT NULL

)

Open in new window

0
 
LVL 22

Accepted Solution

by:
Om Prakash earned 500 total points
ID: 33499097
Try using the following query:

Select DueDate, DeliveryDate,OrderNum
From
      Invnum
Where OrderNum  in (select OrderNum from Items) and DocState in (1,3)
and OrderNum in (SELECT SOno FROM vuForInvNumTrig WHERE (isnull(NoOfCntAllc,0) > isnull(Recd,0)) AND (POno = 'PO7943') AND SOno IS NOT NULL)

If you simply want to supress the warning then set the following before script
SET ANSI_WARNINGS OFF

and reset at the end.
SET ANSI_WARNINGS ON
0
 
LVL 2

Expert Comment

by:ajisasaggi
ID: 33499106
Does the items table have rows with NULL OrderNum value?
If so, add a NOT NULL check for OrderNum and try.

(select OrderNum from Items where OrderNum is not null)
0
 
LVL 6

Expert Comment

by:havj123
ID: 33499151
Try handle null on this Query : select OrderNum from Items

like

select isnull(OrderNum , 0) from Items
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default constraint within a function 3 38
Using CTE to insert records into a table 2 29
SQL Exceptions 3 39
Where to download and how to install sqldmo.dll 5 34
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

14 Experts available now in Live!

Get 1:1 Help Now