SQL Server outer apply causing major CPU burden -


i have user view i've created in sql outer apply brings amount of years experience user has according employment records.

when monitored cost of sql statements in activity monitor (sql enterprise manager) says part in view causing 25% of rather large cpu cost in execution plan.

i'm trying work out more effecient way of bringing metric view without additional overhead.

here apply...

select * users u <blah blah blah> outer apply   (select coalesce (year(getdate()) - min(startyear), 0) yearsworkexp    dbo.job_history    (userid = u.userid)) workexp 

untested have go @ this:

;with base (   select        userid,       min(startyear) startyear   dbo.job_history   group userid )     select u.*      , year(getdate()) - isnull(b.startyear, year(getdate()))  yearsworkexp   users u left outer join base b on b.userid = u.userid; 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -