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)
 Optimization Help

Author  Topic 

srujanavinnakota
Starting Member

34 Posts

Posted - 2013-06-27 : 16:59:08
Below is query I am using. Can somebody help me optimize it ..Please..
Thanks in advance.


SELECT DISTINCT stafffCourse.stafffId, stafffCourse.stafffCourseId, #Terms.stafffTerMId,#Terms.AddDropDate, 1,0
FROM #Terms
INNER JOIN dbo.Schedule WITH (NOLOCK)
ON #Terms.stafffTerMId = Schedule.stafffTerMId
INNER JOIN dbo.stafffCourse WITH (NOLOCK)
ON Schedule.stafffCourseId = stafffCourse.stafffCourseId
INNER JOIN dbo.stafffProgVersion WITH (NOLOCK)
ON stafffProgVersion.ProgramVersionID = stafffCourse.ProgramVersionID
INNER JOIN dbo.stafffClassSched WITH (NOLOCK)
ON Schedule.AdClassSchedID = stafffClassSched.AdClassSchedID and stafffClassSched.adDeliveryMethodID=2
INNER JOIN dbo.stafff WITH (NOLOCK)
ON stafffCourse.stafffId = stafff.stafffId
INNER JOIN dbo.DataStaging WITH (NOLOCK)
ON CsteCollegeOnlineDataStaging.staffNum=stafff.staffNum
WHERE
(
(
dbo.cstfn_StatusAsOfDateAdded(stafffCourse.stafffCourseId,
CASE
WHEN LEFT(Sdf1,1) = 'L' THEN
CASE WHEN Cast(REPLACE(Section, 'M', '') as INT)>= CAST('2000' AS INT)
and CampusCode IN ('00929', '00933', '00962', '00963', '00964', '00965', '00967', '00968', '00978', '00984', '00988')
THEN #Terms.AddDropDate + 8
WHEN Cast(REPLACE(Section, 'M', '') as INT)>= CAST('3000' AS INT)
and CampusCode IN ('00575', '00576' , '00975')
THEN #Terms.AddDropDate + 8
else
#Terms.AddDropDate + 2 end
ELSE #Terms.StartDate + 2
END) = 13 )
OR (dbo.[cstfn_StatusAsOfEffectiveDate](stafffCourse.stafffCourseId,Schedule.StartDate,
CASE WHEN LEFT(Sdf1,1) = 'L' THEN
CASE WHEN Cast(REPLACE(Section, 'M', '') as INT)>= CAST('2000' AS INT)
and CampusCode IN ('00929', '00933', '00962', '00963', '00964', '00965', '00967', '00968', '00978', '00984', '00988')
THEN #Terms.AddDropDate + 8
WHEN Cast(REPLACE(Section, 'M', '') as INT)>= CAST('3000' AS INT)
and CampusCode IN ('00575', '00576' , '00975')
THEN #Terms.AddDropDate + 8 else
#Terms.AddDropDate + 2 end
ELSE #Terms.StartDate + 2
END) = 13))

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-28 : 00:44:50
unless we know what requirement is or atleast see the execution plan its quite difficult to analyse. Can you post the graphical execution plan as a image or provide us with some insight into your actual requirement with some data in below format?

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-06-28 : 04:35:31
I would start looking in function dbo.cstfn_StatusAsOfDateAdded
It's probably a multiline scalar function and thus very bad for performance. Try to rewrite it as ITVF.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -