isuckatsql (10/4/2013)
I have the following sp which is being slowed down by the following count statement:-(select COUNT(*) from EMPLOYMENT_OPPORTUNITIES_CTE) as TotalCount FROM (
No offense but you have a lot more in that code than that single statement that is making it slow.
You have tons of correlated subqueries. These would be better as joins instead.
You are using a catch all type of query which can be horrible for performance. http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]
Not a performance issue but do you understand all the ramification behind NOLOCK? If possible duplicate and/or missing rows is acceptable then this hint might be ok.
Why the MAXDOP?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/