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 OrgConversion2013 April Apr 66.602013 August Aug 0.002013 December Dec 0.002013 February Feb 77.702013 January Jan 73.902013 July Jul 0.002013 June Jun 100.002013 March Mar 70.802013 May May 64.202013 November Nov 0.002013 October Oct 0.002013 September Sep 0.00
Query: --SET ANSI_NULLS OFF--GODeclare @StartDate DateTime, @EndDate DateTime, @Hospital varchar(5), @OrgId Uniqueidentifier;Set @StartDate = '1/1/2013'Set @EndDate = '12/31/2013'--Set @Hospital = NullSet @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 OrgConversionFrom 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