Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Null Value Elimainted by aggregate ...

Author  Topic 

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-06-04 : 13:00:41
Good morning!

I have query that fails during the Job Agent in the morning, but if I run it manually it works fine and creates the table I need it to. The Warning I get in the history log is (see subject line).

I feel like I've wrapped all the appropriate fields correctly in an isnull() function. When the query is complete it doesn't show NULL values but 0.00 where I put the isnull() function.

My Question is: do you see anything wrong with this query? And how do I get the Job to complete?

Table output:
Year Name Mon OrgConversion
2013 April Apr 66.60
2013 August Aug 0.00
2013 December Dec 0.00
2013 February Feb 77.70
2013 January Jan 73.90
2013 July Jul 0.00
2013 June Jun 100.00
2013 March Mar 70.80
2013 May May 64.20
2013 November Nov 0.00
2013 October Oct 0.00
2013 September Sep 0.00


Query:  
--SET ANSI_NULLS OFF
--GO

Declare
@StartDate DateTime
, @EndDate DateTime
,
@Hospital varchar(5)
, @OrgId Uniqueidentifier;

Set @StartDate = '1/1/2013'
Set @EndDate = '12/31/2013'
--Set @Hospital = Null
Set @OrgId = 'EC9A1087-AB10-40bf-851E-AB8027E888CD'


--Select Mon, Isnull(OrgConversion,0.00) as OrgConversion
----Into #OrganConversion
--From (

Select
-- @Hospital as Hospital
--,
m.Year
--, m.Month
, m.Name
, m.Mon
, isnull((Case When (SUM(t.Eligible) + SUM(t.DCD) + SUM(t.Over70Donor)) < 1
Then 0.00
Else CAST(Left((SUM(t.OrganOutcome) / Cast((SUM(t.Eligible) + SUM(t.DCD) + SUM(t.Over70Donor))as Decimal(10,2)))*100,4)
as Decimal(18,2))
END),0.00) as OrgConversion
From dbo.udf_DT_MonthsTAB(@StartDate, @EndDate) m
Left outer Join

(
Select
dbo.DNA_CaseDateTime(dr.Id) as ReferralDate
,

Case When dr.OrganOutcome = '9F412456-90D3-4D84-AA37-EF69FCBB2C61' Then 1 Else 0 End as OrganOutcome
, Case When dr.CmsEligible = 1 Then 1 Else 0 End as Eligible
, Case When (dr.DcdCriteriaMet = 1 AND dr.OrganOutcome = '9F412456-90D3-4D84-AA37-EF69FCBB2C61') Then 1 Else 0 end as DCD
, Case When (p.Age >70 AND dr.OrganOutcome = '9F412456-90D3-4D84-AA37-EF69FCBB2C61') Then 1 Else 0 End as Over70Donor

From Referral r
Inner Join Organization o ON o.Id = r.ReferringOrganizationId
Left Outer Join DonorReferral dr ON dr.PatientId = r.PatientId
Left Outer Join Patient p ON p.Id = r.PatientId
WHERE o.ShortName = @Hospital OR @Hospital is null
AND dbo.DNA_ToMountainDateTime(r.ReferredOn) >= @StartDate
AND dbo.DNA_ToMountainDateTime(r.ReferredOn) <= @EndDate
)
t ON t.ReferralDate Between m.StartDT and m.EndDT

Group By m.Year, m.Mon, m.Name



Everyday life brings me back to reality

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-04 : 13:05:49
its just a warning and you can avoid it by setting ANSI_WARNINGS to OFF

http://msdn.microsoft.com/en-us/library/ms190368.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-06-04 : 13:15:29
Thanks! I'll give that shot and get back to you after the director meeting.

Everyday life brings me back to reality
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-06-04 : 14:05:33
Hard to say since you didn't supply your table structure or sample data. But, one possible cause is that one of the tables are you OUTER JOINing too doesn't have a match to the dominant table and is returning a NULL value. You can ignore it, as visakh suggests, or you can get rid of the warning by properly using a COALESCE around columns that could be NULL.
Go to Top of Page

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-06-04 : 14:16:48
so far setting the warning off has worked.

Thank you both!

Everyday life brings me back to reality
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-05 : 00:02:43
quote:
Originally posted by LarryC74

so far setting the warning off has worked.

Thank you both!

Everyday life brings me back to reality


welcome
Lamprey also has a point in there so see if you've any undesired NULLs coming and handle them using COALESCE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-06-05 : 11:48:06
When I set the Warnings off, it failed...but it showed me what the problem was. I had overlooked a "scheduled" job that is later than this one, but the query in question feed off a table in the latter job.

all is well!!!

Thank you again!

Everyday life brings me back to reality
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-05 : 13:52:37
quote:
Originally posted by LarryC74

When I set the Warnings off, it failed...but it showed me what the problem was. I had overlooked a "scheduled" job that is later than this one, but the query in question feed off a table in the latter job.

all is well!!!

Thank you again!

Everyday life brings me back to reality


ok..good that you got it sorted

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -