Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this Routine Be Faster?
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00801022
Message ID:
00801147
Views:
14
Michael

Thanks for the pointer. I changed it to the following derived table and it works great 0 seconds on the SA. I'm still not sure exactly why the UDF was so expensive, I looked at the show plan, and it showed the highest cost (percentage under the icon) was 51% on the where clause iscompleted=1. I took that out, and it made no difference, I couldn't see anything in the plan that directly showed the UDF.
select 	count(det.proc_Code) as CaseCount,
	det.proc_code,
	det.Proc_Description,
	avg(det.avg_Minutes) as Avg_Minutes,
	avg(det.avgORCost) as AvgORCost,
	avg(det.SumResCost) as AvgResCost,
	det.ProcID 
from 
	(SELECT TOP 100 PERCENT 
		dbo.coproc.dcode as Proc_Code, 
		dbo.coproc.description as Proc_Description,
		datediff(mi,meetings.enteror,meetings.exitor) as Avg_Minutes,
		datediff(mi,meetings.enteror,meetings.exitor) * meetings.DeptCostPerMinute as AvgORCost,
		sum(coCaseData.calculatedCost) as SumResCost,
		dbo.coProc.procid as ProcID
	FROM    dbo.meetings INNER JOIN
	        dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN
		dbo.coCaseData on dbo.meetings.MeetingNumber = dbo.coCaseData.MeetingNumber inner Join
	        dbo.coproc ON dbo.meetproc.procid = dbo.coproc.procid 
	WHERE   (dbo.meetings.iscompleted = 1) 
	and     dbo.meetings.begintime between @ltQueryFrom and @ltQueryTo 
	and 	meetings.deptID=@lnDeptID
	group by dbo.meetings.meetingnumber,coProc.dcode,dbo.coProc.Description,
coProc.procid,dbo.meetings.enterOr,dbo.meetings.ExitOR,dbo.meetings.DeptCostPerMinute
	order by dbo.meetings.meetingnumber) det
group by proc_Code,Proc_Description,ProcID
order by 1 desc
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform